Jump to content

IJVM

From Wikipedia, the free encyclopedia

IJVM is an instruction set architecture created by Andrew Tanenbaum for his MIC-1 architecture. It is used to teach assembly basics in his book Structured Computer Organization.

IJVM is mostly a subset of the JVM assembly language that is used in the Java platform. This instruction set is so simple that it's difficult to write complex programs in it (for example, no shift instructions are provided).

IJVM Instructions

[edit]
Mnemonic Operands Description
BIPUSH byte Push a byte onto stack
DUP N/A Copy top word on stack and push onto stack
ERR N/A Print an error message and halt the simulator
GOTO label name Unconditional jump
HALT N/A Halt the simulator
IADD N/A Pop two words from stack; push their sum
IAND N/A Pop two words from stack; push Boolean AND
IFEQ label name Pop word from stack and branch if it is zero
IFLT label name Pop word from stack and branch if it is less than zero
IF_ICMPEQ label name Pop two words from stack and branch if they are equal
IINC variable name, byte Add a constant value to a local variable
ILOAD variable name Push local variable onto stack
IN N/A Reads a character from the keyboard buffer and pushes it onto the stack. If no character is available, 0 is pushed
INVOKEVIRTUAL method name Invoke a method, pops object reference and optionally pops arguments from stack.
IOR N/A Pop two words from stack; push Boolean OR
IRETURN N/A Return from method with integer value
ISTORE variable name Pop word from stack and store in local variable
ISUB N/A Pop two words from stack; subtract the top word from the second to top word, push the difference;
LDC_W constant name Push constant from constant pool onto stack
NOP N/A Do nothing
OUT N/A Pop word off stack and print it to standard out
POP N/A Delete word from top of stack
SWAP N/A Swap the two top words on the stack
WIDE N/A Prefix instruction; next instruction has a 16-bit index

There's also a set of special ARRAY instructions.

Instruction Stack before* Stack after Description
NEWARRAY count arrayref Create new array on the heap. The count must be of type int. It is popped off the operand stack. The count represents the number of elements in the array to be created. Based on the Sun JVM-spec. The atype parameter is omitted.
IALOAD index. arrayref value Load from int array. The arrayref must be of type reference and must refer to an array whose components are of type int. The index must be of type int. Both arrayref and index are popped from the operand stack. The int value in the component of the array at index is retrieved and pushed onto the operand stack. Part of the Sun JVM Spec.
IASTORE value, index, arrayref ... Store into int array. The arrayref must be of type reference and must refer to an array whose components are of type int. Both index and value must be of type int. The arrayref, index, and value are popped from the operand stack. The int value is stored as the component of the array indexed by index. Part of the Sun JVM Spec.
W_OUT value ... Pop the value from the stack and write a decimal representation of it to the display. For debugging purposes. Not part of the JVM Spec.

*where the first value was pushed on the stack first, so the top of the stack is the operand at the bottom of the lists shown above.

Operand descriptions

  • byte: A numeric literal, in octal (032 - leading zero), decimal (26 - no leading digits), or hexadecimal (0x1A - leading zero-x) format. Character literals ('M - leading single quote) are also allowed. Compiled to a 1-byte constant.
  • label name: The string name of a label. Compiled to a 2-byte offset.
  • variable name: The string name of a local variable. Compiled to a 1-byte value, indicating an offset into the local variable frame.
  • method name: The string name of a method. When compiled, the address of the method is calculated and put into the constant pool. This operand is then replaced with the 2-byte index (in the constant pool) of the address.
  • constant name: The string name of a constant. Compiled to a 2-byte index.
  • N/A: This instruction takes no operands.
[edit]
  • mic1 Free and open source MIC-1 microarchitecture simulator and IJVM assembler.
  • emuIJVM Open source and free, with a stack animation IJVM simulator developed by students at the University of Catania (for Windows, Mac, Linux)
  • A Vrije Universiteit Amsterdam course assignment on implementing an interpreter/ emulator for the IJVM instruction set