My compiler can output bytecode for a stack based virtual machine. These are all the instructions:
Byte | Instruction Name | Description |
---|---|---|
0x00 | NOP | Does nothing |
0x01 | DUP | Duplicates the top value and pushes it on the stack |
0x02 | SWAP | Swaps the top two values on the stack |
0x03 | IGNORE | Pops the top value from the stack |
0x04 | ZERO | Pushes a 0 on the stack |
0x05 | MINUS_ONE | Pushes a -1 on the stack |
0x06 | ONE | Pushes a 1 on the stack |
0x07 | CONSTT x | Pushes tiny constant x on the stack |
0x08 | CONSTS x | Pushes short constant x on the stack |
0x09 | CONSTL x | Pushes long constant x on the stack |
0x0a | CONSTI x | Pushes int constant x on the stack |
0x0b | INSTR x | Pushes instruction address x on the stack |
0x0c | INSTRF x | Pushes address of foreign instruction index x on the stack |
0x0d | DATA x | Pushes data address x on the stack (relative to data segment) |
0x0e | LOCAL x | Pushes local address x on the stack (relative to stack frame) |
0x0f | GLOBAL x | Pushes global address x on the stack (relative to global allocation) |
0x10 | GLOBALF x | Pushes address of foreign global index x on the stack |
0x11 | LOADT | Pushes tiny at top address on the stack |
0x12 | LOADS | Pushes short at top address on the stack |
0x13 | LOADL | Pushes long at top address on the stack |
0x14 | LOADI | Pushes int at top address on the stack |
0x15 | LOADTLOCAL x | Pushes tiny at local address x on the stack |
0x16 | LOADSLOCAL x | Pushes short at local address x on the stack |
0x17 | LOADLLOCAL x | Pushes long at local address x on the stack |
0x18 | LOADILOCAL x | Pushes int at local address x on the stack |
0x19 | LOADTGLOBAL x | Pushes tiny at global address x on the stack |
0x1a | LOADSGLOBAL x | Pushes short at global address x on the stack |
0x1b | LOADLGLOBAL x | Pushes long at global address x on the stack |
0x1c | LOADIGLOBAL x | Pushes int at global address x on the stack |
0x1d | STORET | Stores tiny at top address at second into top address |
0x1e | STORES | Stores short at top address at second into top address |
0x1f | STOREL | Stores long at top address at second into top address |
0x20 | STOREI | Stores int at top address at second into top address |
0x21 | STORETLOCAL x | Stores tiny from local address x into top address |
0x22 | STORESLOCAL x | Stores short from local address x into top address |
0x23 | STORELLOCAL x | Stores long from local address x into top address |
0x24 | STOREILOCAL x | Stores int from local address x into top address |
0x25 | STORETGLOBAL x | Stores tiny from global address x into top address |
0x26 | STORESGLOBAL x | Stores short from global address x into top address |
0x27 | STORELGLOBAL x | Stores long from global address x into top address |
0x28 | STOREIGLOBAL x | Stores int from global address x into top address |
0x29 | MOVET | Moves tiny at top address into second to top address |
0x2a | MOVES | Moves short at top address into second to top address |
0x2b | MOVEL | Moves long at top address into second to top address |
0x2c | MOVEI | Moves int at top address into second to top address |
0x2d | DROP x | Reads top pointer and pushes x bytes to stack |
0x2e | TAKE x | Pops x bytes from stack and stores at top pointer |
0x2f | COPY x | Copies x bytes from top pointer to second to top pointer on the stack |
0x30 | CLEAR x | Clears x bytes at top pointer |
0x31 | SET x y | Sets x bytes to y at top pointer |
0x32 | JMP x | Jumps to instruction x |
0x33 | JMPF x | Jumps to instruction x if top value is 0 |
0x34 | JMPT x | Jumps to instruction x if top value is 1 |
0x35 | JMPD | Jumps to top value |
0x36 | ADD | Adds top two values |
0x37 | SUB | Subtracts top two values |
0x38 | MUL | Multiplies |
0x39 | DIV | Divides |
0x3a | MOD | Modulus |
0x3b | UDIV | Performs unsigned division |
0x3c | UMOD | Performs unsigned modulus |
0x3d | ADDF | Adds float values |
0x3e | ADDR | Adds real values |
0x3f | SUBF | Subtracts float values |
0x40 | SUBR | Subtracts real values |
0x41 | MULF | Multiplies float values |
0x42 | MULR | Multiplies real values |
0x43 | DIVF | Divides float values |
0x44 | DIVR | Divides real values |
0x45 | INC | Increments top value |
0x46 | DEC | Decrements top value |
0x47 | NEG | Negates int |
0x48 | NEGF | Negates float |
0x49 | NEGR | Negates real |
0x4a | LNOT | Logical not |
0x4b | SIGNT | Sign extends tiny |
0x4c | SIGNS | Sign extends short |
0x4d | SIGNL | Sign extends long |
0x4e | TRUNCT | Truncates to tiny |
0x4f | TRUNCS | Truncates to short |
0x50 | TRUNCL | Truncates to long |
0x51 | AND | Bitwise and |
0x52 | OR | Bitwise or |
0x53 | XOR | Bitwise xor |
0x54 | NOT | Bitwise not |
0x55 | LSH | Left shift |
0x56 | RSH | Right shift |
0x57 | LT | Less than |
0x58 | LTEQ | Less than or equal |
0x59 | ULT | Unsigned less than |
0x5a | ULTEQ | Unsigned less than or equal |
0x5b | EQ | Equal |
0x5c | NEQ | Not equal |
0x5d | EQA | Equal (array) |
0x5e | NEQA | Not equal (array) |
0x5f | LTF | Less than (float) |
0x60 | LTR | Less than (real) |
0x61 | LTEQF | Less than or equal (float) |
0x62 | LTEQR | Less than or equal (real) |
0x63 | EQF | Equal (float) |
0x64 | EQR | Equal (real) |
0x65 | NEQF | Not equal (float) |
0x66 | NEQR | Not equal (real) |
0x67 | F2I | Converts float to int |
0x68 | I2F | Converts int to float |
0x69 | R2I | Converts real to int |
0x6a | I2R | Converts int to real |
0x6b | F2R | Converts float to real |
0x6c | R2F | Converts real to float |
0x6d | CALL x | Calls instruction x |
0x6e | CALLF x | Calls foreign instruction index x |
0x6f | CALLD | Calls top value |
0x70 | PUSH x | Pushes stack frame x bytes |
0x71 | PARAM x | Pops stack frame x bytes to place x bytes of parameters into stack frame |
0x72 | RETV | Pops the stack frame and returns the top value |
0x73 | RETB x | Pops the stack frame and returns x bytes |
0x74 | RET | Pops the stack frame and returns |
0x75 | HALT | Halts program |
Arguments of instructions are always 32-bit integers, unless stated otherwise in the description. For example, the CONSTT instruction takes a signed 8-bit integer. Also, all numbers are stored in little-endian format. To get a clearer idea of how this virtual machine works, you can also look at the source code of my simple virtual machine.