/* * Instruction word format: * |31 <- Bit position -> 0| * |INS7|INS6|INS5|INS4|INS3|INS2|INS1|INS0| * ----------------------------------------- * |INS7|INS6|INS5|INS4|INS3|INS2|INS1|0000| INS0 = NOP * |INS7|INS6|INS5|INS4|INS3|INS2|INS1|0100| INS0 = PLUS * |INS7|INS6|INS5|INS4|INS3|INS2|INS1|1000| INS0 = DUP * |INS7|INS6|INS5|INS4|INS3|INS2|INS1|1100| INS0 = SWAP * |LLLL|LLLL|LLLL|LLLL|LLLL|LLLL|LLLL|LL01| LITERAL (30 bit data) * |OOOO|OOOO|OOOO|OOOO|OOOO|OOOO|OOOO|OO10| QBRANCH (32 bit offset) * |AAAA|AAAA|AAAA|AAAA|AAAA|AAAA|AAAA|AA11| CALL (32 bit address) * * The destination of QBRANCH and CALL is a word (4 byte) aligned address. * * Literals > 3FFFFFFF can be pushed on the stack in multiple steps. * 00000000 - 3FFFFFFF LITERAL (n) * 40000000 - 7FFFFFFE LITERAL (n-3FFFFFFF) LITERAL 3FFFFFFF PLUS * 7FFFFFFF - BFFFFFFF LITERAL (n-40000000) * C0000000 - FFFFFFFF LITERAL (~n) NOT */ #define NOOP 0x0 /* ( -- ) No operation */ #define AND 0x1 /* ( n1 n2 -- n3 ) n3 = n1 & n2 */ #define XOR 0x2 /* ( n1 n2 -- n3 ) n3 = n1 ^ n2 */ #define NOT 0x3 /* ( n1 -- n2 ) n2 = ~n1 */ #define PLUS 0x4 /* ( n1 n2 -- n3 ) n3 = n1 + n2 */ #define STORE 0x5 /* ( x a -- ) Write word x to address a */ #define FETCH 0x6 /* ( a -- x ) Read word x from address a */ #define EXIT 0x7 /* ( R: a -- ) Return from a CALL */ #define DUP 0x8 /* ( x -- x x ) Duplicate top cell */ #define DROP 0x9 /* ( x -- ) Remove top cell */ #define TOR 0xa /* ( x -- ) ( R: -- x ) Move cell to return stack */ #define RFROM 0xb /* ( -- x ) ( R: x -- ) Move cell from return stack */ #define SWAP 0xc /* ( x1 x2 -- x2 x1 ) Exchange top two cells */ #define RSHIFT 0xd /* ( n1 -- n2 ) n2 = n1 >> 1 (arithmetic) */ #define LRSHIFT 0xe /* ( n1 -- n2 ) n2 = n1 >> 1 (logical) */ #define HALT 0xf /* ( -- ) Halt execution */ /* INS0 restricted operations */ #define LITERAL 0x1 /* ( -- x ) */ #define QBRANCH 0x2 /* ( f -- ) */ #define CALL 0x3 /* ( R: -- a ) */ /* Cell size in bytes */ #define CELL_SIZE 4 /* Instruction pipe size in instructions - must be >= 2 */ #define PIPE_SIZE 8 /* Stack size in cells must be a power of 2 (default = 16) */ #define DSTACK_CELLS (1 << 4) #define RSTACK_CELLS (1 << 4) #define DSTACK_MASK (DSTACK_CELLS - 1) #define RSTACK_MASK (RSTACK_CELLS - 1)