IJVM Assembly Language Specification

This document describes the syntax of the IJVM Assembly Language, as expected by the mic1 IJVM Assembler. See the summary of IJVM instructions for an explanation of the default IJVM instructions.

Contents
For a more detailed explanation with an example, see the FAQ.

  • Comments

    The IJVM assembler uses C++ style comments: // (double forward slash) indicates the start of a comment. Everything following //, up to the end-of-line character, is treated as a comment.

  • .ijvm file format

    An .ijvm file contains a 32-bit magic number, which identifies the file as a program that can be executed on the mic1 simulator, and any number of data blocks. A data block has three parts, a 32-bit origin that indicates where in memory the block is to be loaded, a 32-bit byte count that indicates how many bytes of data are in the block, and the actual data bytes to be loaded into memory.

    	binary file = <32-bit magic number> [block]*
    	block       = <32-bit origin> <32-bit byte count> 
    
    The 1.0 release of the IJVM Assembler creates two blocks, the constant pool and the program code.

    IJVM Instructions

    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
    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; push their 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

    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 (see 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.