The Java Assembling Language

Jasml Home

User Guide

A Simple Example

Jasml Syntax


Java Macro Instructions

Java Macro Instruction Index




SourceForge.net Logo


Java Macro Instructions

1. Local Variable Instruction

Local variable instructions will operate on local variables, by refering local variable index in the local variable table.

The following instructions use local variables:

ret aload astore dload dstore fload fstore iload istore lload lstore

They should be in such a format:

local_variable_instruction local_variable_name(local_variable_index)

For example:
Consider the following LocalVariableTable:

TestClass this start=line48, end=line75, index=5
java.lang.String s1 start=line0, end=line75, index=0
java.lang.String s2 start=line0, end=line75, index=1]

aload s1(0) or aload 0 , load the localvariable s1 onto the stack.

Sometimes, there is no LocalVariableTable defintions in the class file, in the generated .jasm files, the instructions will be like:

aload unknown-local-variable(local_variable_index)

Indeed, it's only the index in the "(" and ")" that matters, whatever the name of the local variable will not effect the JVM.

Besides, there is another instruction which also operates on local variable, but taking two parameters: innc.

For example:

innc anIntNumber(1) 1 , add local variable at index 1 by 1
innc anIntNumber(1) -1 , substract local variable at index 1 by -1.

2. Branch instructions

Branch instructions are used to branch the execution of JVM to another place. They take label names as parameter.

The following instructions are branch instructions:

goto goto_w if_acmpeq if_acmpne if_icmpeq if_icmpge
if_icmpgt if_icmple if_icmplt if_icmpne ifeq ifge
ifgt ifle iflt ifne ifnonnull ifnull jsr jsr_w

For example,

goto line10

cause the JVM to continue its execution on line10.

3. Method invocation instructions

Method invocation instructions are used to invoke the execution of specific method. They take method names as parameter.

The following instructions are method invocation instructions:

invokespecial invokestatic invokevirtual

The method name must include it's return type, the class it belongs to, its parameters.

For example:

invokevirtual java.lang.StringBuffer java.lang.StringBuffer.append(java.lang.String)

invoke the StringBuffer.append(String s) method

4. Interface method invocation instruction

Interface method invocation instruction is used to invoke interface method. There is only one such instruction: invokeinterface.

It's the same as the method invocation instructions, only that there's an extra count value. As to how this count value is calculated, please refer to the Java Virtural Machine Specification.

For example:

invokeinterface void java.lang.Runnable.run() 1

invoke the run method of Runnable on the implementing class.

5. Field access instructions

Field access instructions are used to access instance or static fields of specific class. They take the field name as parameter.

The following instructions are field access instructions:

getfield getstatic putfield putstatic

The filed name must inlcude its type, the class it belongs to, and its name.

For example,

getstatic java.io.PrintStream java.lang.System.out

accesses the java.lang.System.out field.

6. Instructions Operating on Class

These instructions will perform some operation on specific class. They take class names as parameter, including:

anewarray checkcast instanceof new

For example,

new java.lang.String

create a new instance of java.lang.String.

7. Instructions Operating on Array

These instructions are used to create arrays. There are two type of array operations:

The first is newarray, used to create a single dimension array.

For example :

newarray int

will create an array of int.

newarray java.lang.String

will create an array of java.lang.String.

The second is multianewarray, used to create multi-dimension array.

For example :

multianewarray java.lang.String[ ][ ] 2

the same as defining a String array with String[ ][ ] s = new String[10][11]

multianewarray java.lang.String[ ][ ] 1

the same as defining a String array with String[ ][ ] s = new String[10][ ]

8. Instructions Operating on Numbers and Strings

These instructions is used to push a number or String onto the stack, they take a number or string as parameter.

These instructions including:

bipush sipush ldc ldc_w ldc2_w

For example :

bipush 3

push int number 2 onto stack

ldc 4.5f

push float number 4.5 onto stack

ldc "abc"

load string "abc" from constant pool and push it onto stack

ldc2_w 3L

load long number 3 from constant pool and push it onto stack

9. tableswitch Instruction

tableswitch instruction is used when comiling the switch clause in .java files. It has the format like:

tableswitch default=default_label, low=low_match, high=high_match, jump_table:match_label_0, match_label_1, match_label_2,match_label_3......match_lable_n

defualt_label is the instruction jvm will branch to if no match is found between the high_match and low_match.

for low_match, jvm will branch to match_label_0,
low_match+1, to match_label_1,
low_match+2, to match_label_2,
high_match, to match_label_n.

The label number in jump_table must equals (high_match-low_match).

For example :

tableswitch default=line49, low=1, high=5, jump_table:line40,line43,line49,line49,line46

for -10, will brach to line49,
1 , to line40,
2 , to line43,
5 , to line46

10. lookupswitch Instruction

lookupswitch is also used when the switch clause in .java files, and is somewhat like tableswitch.

It has the format like:

lookupswitch default=defualt_label, npairs=number_of_cases, jump_table:index1->match_label1,index2->match_label2,....., indexn->match_labeln

default_label will be branched to if there is no match found in the index of jump_table. nparis is the case numbers in the swich clause. Each index->match_label entry specifies that if the index matches the number passed from the switch, the instruction at match_label will executed.

For example:

lookupswitch default=line97, npairs=3, jump_table:1->line88,45->line91,109->line94

for -10, will brach to line97,
1, to line88,
45, to line91,
109, to line94

11. Instructions take No Parameter

The following instructions take no parameters:

aaload aastore aconst_null aload_0 aload_1 aload_2 aload_3 areturn arraylength astore_0 astore_1 astore_2 astore_3 athrow baload bastore breakpoint caload castore d2f d2i d2l dadd daload dastore dcmpg dcmpl dconst_0 dconst_1 ddiv dload_0 dload_1 dload_2 dload_3 dmul dneg drem dreturn dstore_0 dstore_1 dstore_2 dstore_3 dsub dup dup2 dup2_x1 dup2_x2 dup_x1 dup_x2 f2d f2i f2l fadd faload fastore fcmpg fcmpl fconst_0 fconst_1 fconst_2 fdiv fload_0 fload_1 fload_2 fload_3 fmul fneg frem freturn fstore_0 fstore_1 fstore_2 fstore_3 fsub i2d i2f i2l iadd iaload iand iastore iconst_0 iconst_1 iconst_2 iconst_3 iconst_4 iconst_5 iconst_m1 idiv iload_0 iload_1 iload_2 iload_3 imul ineg int2byte int2char int2short ior irem ireturn ishl ishr istore_0 istore_1 istore_2 istore_3 isub iushr ixor l2d l2f l2i ladd laload land lastore lcmp lconst_0 lconst_1 ldiv lload_0 lload_1 lload_2 lload_3 lmul lneg lor lrem lreturn lshl lshr lstore_0 lstore_1 lstore_2 lstore_3 lsub lushr lxor monitorenter monitorexit nop pop pop2 return saload sastore swap

Copyright 2006 - Jiang Yang , All Rights Reserved