Jasmin is not a JVM, it is a Java bytecode assembler.
Since it is deployed as a JAR you need the JRE1 to use it, however installing the whole JDK2 may be a better choice since you are going to develop with Java anyway.
To run it, assuming java
is in your PATH environment var you can:
Move to the directory where jasmin.jar
is located and run
java -jar jasmin.jar <input>
Edit your CLASSPATH environment var to include the jasmin.jar
filename and then run the command above anywhere.
In order to fully understand the directives of Jasmin you are better of reading something about the Java class file format3, particularly about the various sections: header, constant pools, attributes, methods4, fields.
Finally you need to learn the byte code instructions.
Be careful that Jasmin is not a simple, low level, assembler.
For example it completely abstracts the constant pool from instructions like getXXX
and invokeXXX
.
Also some instructions have different names (e.g. invokenonvirtual
<-> invokespecial
), see here for a full listing.
Finally a solid knowledge of the JLS and CLASS file format is necessary, specifically of how generics and inner classes are implemented.
A simple helloworld.j
.bytecode 51.0 ;Java 7
.class public helloworld
.super java/lang/Object
.method public static main([Ljava/lang/String;)V
.limit stack 2 ;Max stack depth
.limit locals 1 ;Locals + args = 0 + 1 = 1
getstatic java/lang/System/out Ljava/io/PrintStream;
;Stack: System.out object
ldc "Hello world!"
;Stack: System.out object, string
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
;Stack: /
return
.end method
Note that this class has no constructor.
You can assemble and run this program with
java -jar jasmin.jar helloworld.j
java helloworld
1 The set of binaries to execute Java applications.
2 The set of binaries to develop Java applications, this includes the JRE.
3 An overview on Wikipedia.
4 The code of a method is actually an attribute of the former.