Instruction Set
Stack Operations (0x0*)
// Stack operation opcodes
const NOP: u8 = 0x00; // No operation
const PUSH1: u8 = 0x01; // Push 1 byte
const PUSH8: u8 = 0x02; // Push 8 bytes
const POP: u8 = 0x03; // Remove top item
const DUP: u8 = 0x04; // Duplicate nth item
const SWAP: u8 = 0x05; // Swap with nth item
Opcode | Name | Description | Gas |
---|---|---|---|
0x00 | NOP | No operation | 1 |
0x01 | PUSH1 | Push 1-byte value onto stack | 2 |
0x02 | PUSH8 | Push 8-byte value onto stack | 3 |
0x03 | POP | Remove top stack item | 1 |
0x04 | DUP | Duplicate nth stack item | 2 |
0x05 | SWAP | Swap with nth stack item | 2 |
Math Operations (0x1*)
// Math operation opcodes
const ADD: u8 = 0x10; // Add top two items
const SUB: u8 = 0x11; // Subtract
const MUL: u8 = 0x12; // Multiply
const DIV: u8 = 0x13; // Divide
const MULDIV: u8 = 0x14; // (a * b) / c
const MIN: u8 = 0x15; // Minimum
const MAX: u8 = 0x16; // Maximum
Opcode | Name | Description | Gas |
---|---|---|---|
0x10 | ADD | Add top two stack items | 2 |
0x11 | SUB | Subtract top from second | 2 |
0x12 | MUL | Multiply top two items | 3 |
0x13 | DIV | Divide second by top | 3 |
0x14 | MULDIV | Multiply then divide | 4 |
0x15 | MIN | Push minimum value | 2 |
0x16 | MAX | Push maximum value | 2 |
Memory Operations (0x2*)
// Memory operation opcodes
const LOAD: u8 = 0x20; // Load from memory
const STORE: u8 = 0x21; // Store to memory
const LOADN: u8 = 0x22; // Load n bytes
const STOREN: u8 = 0x23; // Store n bytes
const MSIZE: u8 = 0x24; // Get memory size
Opcode | Name | Description | Gas |
---|---|---|---|
0x20 | LOAD | Load 8 bytes from memory | 3 |
0x21 | STORE | Store 8 bytes to memory | 3 |
0x22 | LOADN | Load n bytes from memory | 3+n |
0x23 | STOREN | Store n bytes to memory | 3+n |
0x24 | MSIZE | Push memory size | 1 |
Control Flow (0x3*)
// Control flow opcodes
const JUMP: u8 = 0x30; // Jump to address
const JUMPI: u8 = 0x31; // Conditional jump
const CALL: u8 = 0x32; // Call subroutine
const RETURN: u8 = 0x33; // Return from call
Opcode | Name | Description | Gas |
---|---|---|---|
0x30 | JUMP | Jump to address | 4 |
0x31 | JUMPI | Conditional jump | 5 |
0x32 | CALL | Call subroutine | 10 |
0x33 | RETURN | Return from call | 5 |
Solana Operations (0x4*)
// Solana operation opcodes
const TRANSFER: u8 = 0x40; // Transfer SOL
const SPLOP: u8 = 0x41; // SPL token ops
const CPI: u8 = 0x42; // Cross-program
const LOG: u8 = 0x43; // Log to output
Opcode | Name | Description | Gas |
---|---|---|---|
0x40 | TRANSFER | Transfer SOL between accounts | 100 |
0x41 | SPLOP | SPL token operations | 200 |
0x42 | CPI | Cross-program invocation | 500 |
0x43 | LOG | Log value to output | 5 |