Below we list the instructions of the iJVM and their semantics. Given an iJVM state s where the next instruction to execute is inst (that is the pc points to inst), the semantics (meaning) of the iJVM instructions specify how we obtain the next state, the state obtained by executing inst.
In all of the instructions below, unless we say otherwise, executing an instruction results in a state where the pc of the top frame is incremented by 1. In addition, all of the arithmetic and logical operations are on 32 bit signed numbers. As per the discussion on bit vectors, we represent bit vectors as numbers. In addition, unless we say otherwise, when we refer to local variables and/or the local stack, we mean of the top frame. The semantics of the iJVM closely mimicks the semantics of the corresponding JVM instructions; the official specification of the JVM is maintained by Sun at http://java.sun.com/docs/books/vmspec/.
Instruction |
Meaning (how to obtain the next state) |
(NOP) |
No effect (besides incrementing the pc) |
(ILOAD n) |
N should be the name of a local variable; push the
value of n onto the local stack. |
(ISTORE n) |
N should be the name of a local variable; store the top
of the local stack in n and pop the local stack. Recall
that the local variables are an alist mapping symbols to integers.
Use the function bind you were asked to define previously. |
(BIPUSH v) |
Push v onto the local stack. |
(POP) |
Pop the local stack. |
(DUP) |
Push the top of the local stack onto the local
stack, i.e., duplicate the top of the local stack. |
(SWAP) |
Swap the top two elements of the local stack. |
(ISUB) |
Subtract the top of the local stack from the second number
on the stack; pop the two numbers from the stack and push the
result. |
(IADD) |
Add the top two elements of the stack; remove the
two numbers from the stack and push the result. |
(IMUL) |
Multiply the top two elements of the stack; remove the
two numbers from the stack and push the result. |
(IAND) |
And the top two elements of the stack; remove the
two numbers from the stack and push the result. |
(IOR) |
Or the top two elements of the stack; remove the
two numbers from the stack and push the result. |
(GOTO a) |
Set pc to pc+a |
(IFEQ a) |
If the top of the local stack is 0, set the pc to
pc+a; otherwise, set the pc to pc+1.
In either case, pop the stack. |
(IFNE a) |
If the top of the local stack is not 0, set the pc to
pc+a; otherwise, set the pc to pc+1.
In either case, pop the stack. |
(IFGT a) |
If the top of the local stack is > 0, set the pc to
pc+a; otherwise, set the pc to pc+1.
In either case, pop the stack. |
(INVOKESTATIC c n) |
This instruction is used to invoke a static method, also called a class method. C is a string that names the class and n is a string that names the method. Scan c and then the list of its superclasses in order. Find the first class that has a method named n. Let us call this method m, its formals f, and its body b.
If the length of f is i, then the local stack should have at least i integers on it. Starting with the top of the stack, let us name the elements argi, ..., arg2, arg1. (There might be other elements on the stack, below arg1.) The next state is obtained by modifying the current state as follows:
|
(IRETURN) |
Let val be the top of the local stack. Pop the call stack. Push val onto the local stack in the top frame of the resulting call stack. |
(HALT) |
No effect. The pc is unchanged. |