∟AsmTools/JASM Assembly Statements

This section provides a quick introduction on AsmTools/JASM assembly statements.

The AsmTools/JASM assembly language consists of 2 types of statements: declarations and instructions.

Declarations - Declaration statements use Java syntax to declare classes, fields and methods. Here are some examples:

// declares a public class called "HelloWorld"
public class HelloWorld {...}

// declares a public static method called "main"
public static Method main:"([Ljava/lang/String;)V"
  stack 2 locals 1 {...}

// declares try-catch block with a identifier
try TRY_1;
  ...
endtry TRY_1;
goto TRY_1_END;
catch TRY_1;
  ...
  goto ...;
TRY_1_END: ...;

JVM Instructions - Instruction statements start with mnemonics of JVM opcodes, followed by optional parameters. Here are some Examples.

; Load the value from variable slot 0,
; which holds the address of "this" object in an instance method
; No parameter is needed
aload_0;

// Invoke the constructor of the base class.
// The method reference is provided as a single parameter
// which will be moved to the constant pool by the compiler.
invokespecial Method java/lang/Object.<init>:"()V";

// End the the current method with no return value.
return;

// Load the value from class field System.out
// 2 parameters are required: the second identifies the field,
// the first specifies the constant type of the second parameter.
// Both parameters will be moved to the constant pool by the compiler.
getstatic Field java/lang/System.out:"Ljava/io/PrintStream;";

// Load a string constant.
// The string is provided as a parameter,
// which will be moved to the constant pool by the compiler.
ldc String "Hello, World from AsmTools!";

// Invoke the System.out.println() method.
// The method reference is provided as a single parameter
// which will be moved to the constant pool
invokevirtual Method java/io/PrintStream.println:"(Ljava/lang/String;)V";

// Switch to different labels based some sequential integers
// The starting integer is specified next to the opcode.
// Labels for switching targets and default target are specified one per line.
tableswitch {
    Label_l1;
    Label_l2;
    ...
    default: Label_Others
};

// Switch to different labels based some non-sequential integers
// The starting integer is specified next to the opcode.
// Labels for switching targets and default target are specified one per line,
lookupswitch {
  11: Label_l1;
  17: Label_17;
  ...
  default: Label_Others
};

Note that instruction statements can be prefixed labels to be used as targets for flow control statements. Here are some Examples.

LoopCondition: iload_1;   // mark the loop condition
  ifeq LoopEnd;
LoopBody: ...;            // mark the loop body, not really needed
  iinc 1 -1;
  goto LoopCondition;
LoopEnd: ...;             // mark the loop end

Table of Contents

 About This Book

 JVM (Java Virtual Machine) Specification

 Java HotSpot VM - JVM by Oracle/Sun

 java.lang.Runtime Class - The JVM Instance

 java.lang.System Class - The Operating System

 ClassLoader Class - Class Loaders

 Class Class - Class Reflections

 JVM Runtime Data Areas

 JVM Stack, Frame and Stack Overflow

 Thread Testing Program and Result

 CPU Impact of Multi-Thread Applications

 I/O Impact of Multi-Thread Applications

 CDS (Class Data Sharing)

 Micro Benchmark Runner and JVM Options

 Micro Benchmark Tests on "int" Operations

 Micro Benchmark Tests on "long" Operations

 Micro Benchmark Tests in JIT Compilation Mode

 Micro Benchmark Tests on "float" and "double" Operations

 OpenJ9 by Eclipse Foundation

 JRockit JVM 28.2.7 by Oracle Corporation

 JVM Bytecode and Instruction Set

►JVM Assembler/Disassembler Tools

 What Is JVM Assembler

 What Is Jasmin

 Compare HelloWorld.j with "javap" Output

 Jasmin Assembly Statements

 Jasmin Example - Empty.j

 Jasmin Example - Calculator.j

 What Is JASM

 JASM Assembly Statements

 JASM Example - Calculator.jasm

 JASM Disassembler: "jasm -d"

 What Is AsmTools

►AsmTools/JASM Assembly Statements

 AsmTools/JASM Example - Calculator.jasm

 AsmTools/JASM Disassembler: "jdis"

 AsmTools/JCOD Assembly File Format

 AsmTools/JCOD Example - HelloWorld.jcod

 AsmTools/JCOD Disassembler: "jdec"

 What Is Lilac

 Lilac Assembly Statements

 Lilac Macro Example - HelloWorldMacro.jasm

 Lilac Disassembler: "jdasm"

 Archived Tutorials

 References

 Index

 Full Version in PDF/EPUB