Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Opcode Reference

Sizes are in bytes, opcode included. S is the operand stack, top on the right.

Stack and variables

OpcodeMnemonicSizeEffect
0x02POP v2Pop a value into variable slot v.
0x03PUSH tag x3Push a value, see PUSH type tags.
0xA6INC1Add 1 to the top of the stack.
0xA7DEC1Subtract 1 from the top of the stack.
0xA8INCV v2Increment variable slot v.
0xA9DECV v2Decrement variable slot v.
0xABCPY v2Copy the top of the stack into variable slot v without popping it (used for the repeat iterator).
0xDEDEREF1Pop a slot number and push that variable’s value (*r). Stops the VM if the slot does not exist.

PUSH type tags

TagOperand
0x01string pool index
0x02integer constant pool index
0x03variable slot to read
0x04immediate integer (references, JOIN count)
0x05float constant pool index

Arithmetic

All pop two values and push one. Integer operands give an integer; a float operand gives a float. A string operand is a runtime error.

OpcodeMnemonicEffect
0xA0ADDa + b
0xA1SUBa - b
0xA2MULa * b
0xA3DIVa / b (always floating point)
0xA4POWa ^ b
0xA5MODa % b (integer % 0 is a runtime error)
0xAAJOINPop a count n, then join the next n values into one string (..).

Arrays

OpcodeMnemonicSizeEffect
0xDAARRWRITE a2Stack [value, index]: store value in array a, creating or growing it.
0xDBARRREAD a2Stack [index]: push element index of array a.

Errors: negative write index, missing array, index out of range.

Control flow

8-bit vs 32-bit addressing

The current compiler emits only the 32-bit forms (opcode + 4-byte address, 5 bytes). The 8-bit forms (2 bytes) are kept so older programs still run.

8-bit32-bitMnemonicEffect
0x050x06JUMPUnconditional jump.
0x010x07CALLPush a frame and jump to a routine.
0xB00xC0JEQPop b, a; jump if a == b.
0xB10xC1JGRjump if a > b
0xB20xC2JLSjump if a < b
0xB30xC3JGEjump if a >= b
0xB40xC4JLEjump if a <= b
0xB50xC5JNEjump if a != b

Two strings compare lexicographically, other values numerically. Jump targets inside a routine are relative to the routine’s start.

OpcodeMnemonicSizeEffect
0x04EXEC f2Call built-in function f, see Built-in Functions.
0xFERET1Return from a routine.
0xFFHLT1Stop the program.