# # Ace opcode reference # # The following is an assembly language which maps to Ace VM opcodes. # # Instruction names are usually preceded by one of several letters: # # r reference (stored in one slot) or array # b byte (8-bit) or boolean (1-bit) (stored in an int) # c char (Unicode char, stored in an int) # d double (64-bit floating point number, stored in two 32-bit slots) # f float (32-bit floating point number) # i int (32-bit) # l long (64-bit, stored in two 32-bit slots) # s short (stored in an int) # # Descriptions use the following letters: # # a The top slot of the stack. May be an int, float or reference. # b The second stack slot. May be an int, float or reference. # c The third stack slot. May be an int, float or reference. # d The fourth stack slot. May be an int, float or reference. # ab The long or double on top of the stack, made up of slots a and b. # cd The long or double on top of the stack, made up of slots c and d. # # Instructions mostly take no arguments. In these cases the information # is on the stack, or in local variables implied by the instruction name. # # Some instructions take arguments. If the argument is a type: # # Z boolean 4 # C char 5 # F float 6 # D double 7 # B byte 8 # S short 9 # I int 10 # J long 11 # # If the argument is a desc, it can be any of the follow concatenated: # # type a type letter (see above) # [desc an array of things # Lclass; a complete class name (note the letter L and the semicolon) # (desc)V a method which returns void # (desc)desc a method which accepts parameters and returns one parameter # # For instance: # # invokevirtual java/io/PrintStream/println (Ljava/lang/String;)V # getstatic java/lang/Math/PI D # invokeinterface MyInterface/mymethod (JJ[Ljava/lang/String;)D 6 # multinewarray [[I 2 # # Hex Name Arguments Description 00 nop do nothing # Loading constants 01 r_const_null push null reference 10 bi_push n push int (-128...127) 11 si_push n push short int (-32,768...32767) 12 ldc x push x (a constant int, float or String in first 256 constants in pool) 13 ldc_w x push x (a constant int, float or String) 14 ldc2_w x push x (a constant double or long) # Loading variable 15 i_load n push local int variable n 18 d_load n push local double variable n 19 r_load n push local reference variable n 2E ia_load push int array element a from array b 31 da_load push double array element a from array b 32 ra_load push reference array element a from array b # Storing variables 36 i_store n store a in local int variable n 39 d_store n store ab in local double variable n 3A r_store n store a in local reference variable n 4F ia_store store int a in array element b of array c 52 da_store store double ab in array element c of array d 53 ra_store store reference a in array element b of array c # Stack manipulation 57 pop remove a 59 dup duplicate a 5F swap swap a and b # Arithmetic 60 i_add add int (a+b) 63 d_add add double (ab+cd) 64 i_sub subtract int (a-b) 67 d_sub subtract double (ab-cd) 68 i_mul multiply int (a*b) 6B d_mul multply double (ab*cd) 6C i_div divide int (a/b) 6F d_div divide double (ab/cd) 70 i_rem remainder int (a%b) 73 d_rem remainder double (ab%cd) 74 i_neg negate int (-a) 77 d_neg negate double (-ab) 78 i_shl shift int left (a << b) 7A i_shr shift int right (a >> b) 7C i_ushr unsigned shift int right (a >>> b) 7E i_and bitwise int and (a & b) 80 i_or bitwise int or (a | b) 82 i_xor bitwise int xor (a ^ b) 84 i_inc n increment increment local variable n # Conversion 87 i_to_d convert int a to double 8E d_to_i convert double ab to int # Comparison 94 lcmp 95 fcmpl compare float with long 96 fcmpg compare float 97 dcmpl compare double with long 98 dcmpg compare double # Control 99 if_eq label branch if int a == 0 9A if_ne label branch if int a != 0 9B if_lt label branch if int a < 0 9C if_ge label branch if int a >= 0 9D if_gt label branch if int a > 0 9E if_le label branch if int a <= 0 9F if_i_cmpeq label branch if int a == b A0 if_i_cmpne label branch if int a != b A1 if_i_cmplt label branch if int a < b A2 if_i_cmpge label branch if int a >= b A3 if_i_cmpgt label branch if int a > b A4 if_i_cmple label branch if int a <= b A5 if_r_cmpeq label branch if reference a == b A6 if_r_cmpne label branch if reference a != b A7 goto label branch always to label A8 jsr label branch to label; push return location A9 ret n branch to location in variable n AC i_return return int from method AF d_return return double from method B0 r_return return reference from method B1 return return from method # Access B4 getfield class/field desc push object field B5 putfield class/field desc store a in object field B6 invokevirtual class/method desc invoke method virtually # Objects BB new class create new object of class BC newarray type create array of type, length a BD a_newarray class create array of class, length a BE arraylength push length of array BF throw throw exception a C0 checktype class throw exception if a is not an instance of class C1 instanceof class push 1 if a is class, 0 otherwise # Extras C5 multinewarray class n create multidimensional array with first n dimensions initialized to lengths a, b, c...