Java class into Jasmin assembly code

4k Views Asked by At
import java.util.Scanner;

public class Sample {
   public static void main(String []args){
      Scanner scan = new Scanner(System.in);
      int intAge;

      intAge = scan.nextInt();

      System.out.println("Your age is " + lol + " years old.");

      }
}

Is there any way to convert this code into jasmin assembly code? I'm having a hard time to find a way to do it. Answers would be appreciated.

2

There are 2 best solutions below

2
On BEST ANSWER

http://classfileanalyzer.javaseiten.de/
One person project, very old (last update 2009),
But according to wikipedia jasmin's last update is 2010.

I tested it with a simple file it worked.

EDIT : I'am showing the usage and output of sample for completeness of answer. (lol is replaced with intAge in the code above)

java -cp classfileanalyzer-0.8.0.jar ClassFileAnalyzer Sample.class 

; Sample.j

; Generated by ClassFileAnalyzer (Can)
; Analyzer and Disassembler for Java class files
; (Jasmin syntax 2, http://jasmin.sourceforge.net)
;
; ClassFileAnalyzer, version 0.8.0 


.bytecode 51.0
.source Sample.java
.class public Sample
.super java/lang/Object

.method public <init>()V
  .limit stack 1
  .limit locals 1
  .line 3
  0: aload_0
  1: invokespecial java/lang/Object/<init>()V
  4: return
.end method

.method public static main([Ljava/lang/String;)V
  .limit stack 3
  .limit locals 3
  .line 5
  0: new java/util/Scanner
  3: dup
  4: getstatic java/lang/System/in Ljava/io/InputStream;
  7: invokespecial java/util/Scanner/<init>(Ljava/io/InputStream;)V
  10: astore_1
  .line 8
  11: aload_1
  12: invokevirtual java/util/Scanner/nextInt()I
  15: istore_2
  .line 10
  16: getstatic java/lang/System/out Ljava/io/PrintStream;
  19: new java/lang/StringBuilder
  22: dup
  23: invokespecial java/lang/StringBuilder/<init>()V
  26: ldc "Your age is "
  28: invokevirtual java/lang/StringBuilder/append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  31: iload_2
  32: invokevirtual java/lang/StringBuilder/append(I)Ljava/lang/StringBuilder;
  35: ldc " years old."
  37: invokevirtual java/lang/StringBuilder/append(Ljava/lang/String;)Ljava/lang/StringBuilder;
  40: invokevirtual java/lang/StringBuilder/toString()Ljava/lang/String;
  43: invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
  .line 12
  46: return
.end method
0
On

Assuming you don't need to use Jasmin specifically, The Krakatau assembler/disassembler is probably what you want. Krakatau can disassemble classfiles to a Jasmin-like syntax and then assemble them back to classfiles. However, Krakatau uses a slightly different syntax than Jasmin in order to support features that Jasmin can't handle.