1

I have downloaded Jasmin JVM for my assembly language course at university. I am currently having some difficulties.

How do I write .j files: - I have tried writing the files in textedit and eclipse and saving it as a .j file and then moving it into the directory but it wont let me run it from the terminal.

if anyone can help me out, or lead me in the right direction, that would be greatly appreciated.

Margaret Bloom
  • 41,768
  • 5
  • 78
  • 124
rheak
  • 21
  • 1
  • 1
  • 4

1 Answers1

3

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:

  1. Move to the directory where jasmin.jar is located and run

    java -jar jasmin.jar <input>
    
  2. 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.

Margaret Bloom
  • 41,768
  • 5
  • 78
  • 124
  • Thank you, I feel more familiar now with this. I was curious to what kind of text editor do you write the jasmin code in? – rheak Sep 14 '16 at 17:46
  • @rheak Usually the default one: Notepad on Windows, kate on KDE, text editor on OS X. I don't need fancy features when coding with Jasmin, yet I don't write Java byte code asm every day. – Margaret Bloom Sep 14 '16 at 18:03