Home

Awesome

JASM - A JVM Assembler for the modern age

What?

JASM is an assembler/disassembler for JVM bytecode. It provides a nice syntax for writing JVM classes in a bytecode-focused assembly language, and can also disassemble any Java .class file to JASM source code.

JASM has a Gradle plugin and a (WIP) Plugin for IntelliJ.

See the Example Gradle project for an example of how JASM might fit in to your project.

Let's just get this out of the way, shall we?

public class com/example/HelloWorld {
    public static main([java/lang/String)V {
        getstatic java/lang/System.out java/io/PrintStream
        ldc "Hello, World"
        invokevirtual java/io/PrintStream.println(java/lang/String)V
        return
    }
}

See the Examples for more examples of JASM code.

How?

Requirements

Using the Gradle plugin

If you just want to use some JASM code in your own Gradle project, the easiest way to get started is via the Gradle plugin.

For more information and some documentation about the plugin, see the Github repo

Using the command-line tool

If you downloaded a binary distribution then you should be all set. Inside the archive you'll find a `bin/jasm' script that will take care of running the command-line tool for you.

To see usage details:

bin/jasm --help

To simply assemble a file src/com/example/MyClass.jasm to the classes directory:

bin/jasm -i src -o classes com/example/MyClass.jasm

Or to disassemble a .class file classes/com/example/MyClass.class to the src directory:

bin/jasm -d -i classes -o src com/example/MyClass.class

Notice that you set the source and destination directories, and just pass the relative path to the files within them - this is how the assembler creates the output files in the appropriate place (in a com/example directory under the destination directory in the example above).

When disassembling, you can optionally specify the -l flag, which will cause JASM to output comments in the disassembly with the original line number (if this information is present in the .class file).

Building the tool with Gradle

If you grabbed the source from Github you can easily build a binary distribution with ./gradlew clean assemble (pun not intended).

Using JASM as a library

If you want to use this as a library (with Maven or Gradle), you'll want to pull in the dependency from Maven central.

E.g. (for Gradle):

dependencies {
  implementation("com.roscopeco.jasm:jasm:0.7.0")
}

Why??

Well, why not?

I wrote this for fun, which I had both in writing it and playing with it.

If you really need some use-cases to justify the electrons squandered in pursuit of this project, how about these (some lifted from Jasmin's README):

Why not just use Jasmin?

The venerable Jasmin project has been around for years, and has the advantage of being mature, stable, and well supported everywhere (for example, Github does syntax highlighting for it). So why not just use that?

Of course it's totally personal choice which you use, but there are a few reasons to choose JASM over Jasmin:

Who?

JASM is copyright 2022 Ross Bamford (roscopeco AT gmail DOT com).

See LICENSE.md for the gory legal stuff (spoiler: MIT).