|
JASMIN INSTRUCTIONS
Jonathan Meyer, July 1996
IntroductionThis document shows the syntax and the types of parameters required by each Java VM instruction in Jasmin. It also shows brief illustrative examples.See The Jasmin User Guide for a description of other aspects of the Jasmin syntax.
Local variable instructionsThe following instructions use local variables:
ret <var-num>
aload <var-num>
astore <var-num>
dload <var-num>
dstore <var-num>
fload <var-num>
fstore <var-num>
iload <var-num>
istore <var-num>
lload <var-num>
lstore <var-num>
for example:
aload 1 ; push local variable 1 onto the stack
ret 2 ; return to the address held in local variable 2
The bipush, sipush and iinc instructionsThe bipush and sipush instructions take an integer as a parameter:
bipush <int>
sipush <int>
for example:
bipush 100 ; push 100 onto the stack
The iinc instruction takes two integer parameters:
iinc <var-num> <amount>
for example:
iinc 3 -10 ; subtract 10 from local variable 3
Branch instructionsThe following instructions take a label as a parameter:
goto <label>
goto_w <label>
if_acmpeq <label>
if_acmpne <label>
if_icmpeq <label>
if_icmpge <label>
if_icmpgt <label>
if_icmple <label>
if_icmplt <label>
if_icmpne <label>
ifeq <label>
ifge <label>
ifgt <label>
ifle <label>
iflt <label>
ifne <label>
ifnonnull <label>
ifnull <label>
jsr <label>
jsr_w <label>
For example:
Label1:
goto Label1 ; jump to the code at Label1
; (an infinite loop!)
Class and object operationsThe following instructions take a class name as a parameter:
anewarray <class>
checkcast <class>
instanceof <class>
new <class>
For example:
new java/lang/String ; create a new String object
Method invokationThe following instructions are used to invoke methods:
invokenonvirtual <method-spec>
invokestatic <method-spec>
invokevirtual <method-spec>
for example:
; invokes java.io.PrintStream.println(String);
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
A method specification is formed of three parts: the characters before the
last '/' form the class name. The characters between the last '/' and '(' are
the method name. The rest of the string is the descriptor.
foo/baz/Myclass/myMethod(Ljava/lang/String;)V
--------------- ---------------------
| -------- |
| | |
class method descriptor
A special case is invokeinterface, which takes a <method-spec> and
an integer indicating how many arguments the method takes:
invokeinterface <method-spec> <num-args>
for example:
invokeinterface foo/Baz/myMethod(I)V 1
Field manipulation instructionsThe four instructions getfield, getstatic, putfield and putstatic have the form:
getfield <field-spec> <descriptor>
getstatic <field-spec> <descriptor>
putfield <field-spec> <descriptor>
putstatic <field-spec> <descriptor>
for example:
; get java.lang.System.out, which is a PrintStream
getstatic java/lang/System/out Ljava/io/PrintStream;
<field-spec> is composed of two parts, a classname and a fieldname. The
classname is all of the characters in the <field-spec> up to the last
'/' character, and the fieldname is the rest of the characters after the last
'/'. For example:
foo/baz/AnotherClass/anotherFunField
-- class name ------ --field name --
<descriptor> is the Java type descriptor of the field.
For example:
Ljava/io/PrintStream;
The newarray instructionThe newarray instruction is followed by the type of the array,
newarray <array-type>
for example:
newarray int
newarray short
newarray float
etc.
The multianewarray instructionThe multianewarray instruction takes two parameters, the type descriptor for the array and the number of dimensions to allocate:
multianewarray <array-descriptor> <num-dimensions>
for example:
multianewarray [[[I 2
The ldc and ldc_w instructionsThe ldc and ldc_w instructions are followed by a constant:
ldc <constant>
ldc_w <constant>
<constant> is either an integer, a floating point number, or a
quoted string. For example:
ldc 1.2 ; push a float
ldc 10 ; push an int
ldc "Hello World" ; push a String
ldc_w 3.141592654 ; push PI as a double
The lookupswitch instructionThe lookupswitch instruction has the syntax:
<lookupswitch> ::=
lookupswitch
<int1> : <label1>
<int2> : <label2>
...
default : <default-label>
For example:
; If the int on the stack is 3, jump to Label1.
; If it is 5, jump to Label2.
; Otherwise jump to DefaultLabel.
lookupswitch
3 : Label1
5 : Label2
default : DefaultLabel
Label1:
... got 3
Label2:
... got 5
DefaultLabel:
... got something else
The tableswitch instructionThe tableswitch instruction has the syntax:
<tableswitch> ::=
tableswitch <low>
<label1>
<label2>
...
default : <default-label>
For example:
; If the int on the stack is 0, jump to Label1.
; If it is 1, jump to Label2.
; Otherwise jump to DefaultLabel.
tableswitch 0
Label1
Label2
default : DefaultLabel
Label1:
... got 0
Label2:
... got 1
DefaultLabel:
... got something else
No parameterThe following instructions (the majority) take no parameters:
pop ; remove the top item from the stack
iconst_1 ; push 1 onto the stack
swap ; swap the top two items on the stack
Copyright (c) Jonathan Meyer, July 1996 Jasmin Home | Jon Meyer's Home |