Hardware Reference
In-Depth Information
The IJVM instruction set is shown in Fig. 4-11. Each instruction consists of an
opcode and sometimes an operand, such as a memory offset or a constant. The
first column gives the hexadecimal encoding of the instruction. The second gives
its assembly-language mnemonic. The third gives a brief description of its effect.
Hex
Mnemonic
Meaning
0x10
BIPUSH
byte
Push byte onto stack
0x59
DUP
Copy top word on stack and push onto stack
0xA7
GOTO
offset
Unconditional branch
0x60
IADD
Pop two words from stack; push their sum
0x7E
IAND
Pop two words from stack; push Boolean AND
0x99
IFEQ
offset
Pop word from stack and branch if it is zero
0x9B
IFLT
offset
Pop word from stack and branch if it is less than zero
0x9F
IF ICMPEQ
offset
Pop two words from stack; branch if equal
0x84
IINC
varnum const
Add a constant to a local variable
0x15
ILOAD
varnum
Push local variable onto stack
0xB6
INVOKEVIRTUAL
disp
Invoke a method
0x80
IOR
Pop two words from stack; push Boolean OR
0xAC
IRETURN
Return from method with integer value
0x36
ISTORE
varnum
Pop word from stack and store in local variable
0x64
ISUB
Pop two words from stack; push their difference
0x13
LDC W
index
Push constant from constant pool onto stack
0x00
NOP
Do nothing
0x57
POP
Delete word on top of stack
0x5F
SWAP
Swap the two top words on the stack
0xC4 WIDE
Prefix instruction; next instruction has a 16-bit index
Figure 4-11.
The IJVM instruction set. The operands
byte
,
const
, and
varnum
are 1 byte. The operands
disp
,
index
, and
offset
are 2 bytes.
Instructions are provided to push a word from various sources onto the stack.
These sources include the constant pool (
LDC W
), the local variable frame (
ILOAD
),
and the instruction itself (
BIPUSH
). A variable can also be popped from the stack
and stored into the local variable frame (
ISTORE
). Two arithmetic operations (
IADD
and
ISUB
) as well as two logical (Boolean) operations (
IAND
and
IOR
) can be per-
formed using the two top words on the stack as operands. In all the arithmetic and
logical operations, two words are popped from the stack and the result pushed back
onto it. Four branch instructions are provided, one unconditional (
GOTO
) and three
conditional ones (
IFEQ
,
IFLT
, and
IF ICMPEQ
). All the branch instructions, if taken,
adjust the value of
PC
by the size of their (16-bit signed) offset, which follows the
opcode in the instruction. This offset is added to the address of the opcode. There