balanced ternary computer — reference
ISA cheat sheet
Machine control
| NOP | 0 | No state change. PC += 3. |
| HALT | 1 | Sets HALT flag; execution stops. |
Data movement
| MOV Rd, Rs | 2 | Rd <- Rs. Updates SIGN. |
| MOV Rd, value | 3 | Rd <- immediate. Updates SIGN. |
Memory access
| LOAD Rd, [addr] | 4 | Rd <- mem[addr]. Updates SIGN. |
| LOAD Rd, [Rs] | 5 | Rd <- mem[Rs]. Updates SIGN. |
| STORE [addr], Rs | 6 | mem[addr] <- Rs. |
| STORE [Rd], Rs | 7 | mem[Rd] <- Rs. |
Arithmetic
| ADD Rd, Rs | 8 | Rd <- Rd + Rs. Updates SIGN, OVF. |
| ADD Rd, value | 9 | Rd <- Rd + immediate. Updates SIGN, OVF. |
| SUB Rd, Rs | 10 | Rd <- Rd - Rs. Updates SIGN, OVF. |
| SUB Rd, value | 11 | Rd <- Rd - immediate. Updates SIGN, OVF. |
| MUL Rd, Rs | 12 | Rd <- Rd * Rs. Updates SIGN, OVF. |
| MUL Rd, value | 13 | Rd <- Rd * immediate. Updates SIGN, OVF. |
| NEG Rd | 14 | Rd <- -Rd (trit-wise inversion). Updates SIGN. |
| DIV Rd, Rs | 26 | Rd <- round(Rd / Rs), ties away from zero. Updates SIGN, OVF. |
| DIV Rd, value | 27 | Rd <- round(Rd / immediate), ties away from zero. Updates SIGN, OVF. |
| REM Rd, Rs | 28 | Rd <- Rd - DIV(Rd, Rs) * Rs. Updates SIGN, OVF. |
| REM Rd, value | 29 | Rd <- Rd - DIV(Rd, imm) * imm. Updates SIGN, OVF. |
| SHL Rd, Rs | 30 | Rd <- Rs * 3 (shift one trit place left). Updates SIGN, OVF. |
| SHR Rd, Rs | 31 | Rd <- round(Rs / 3) (shift one trit place right). Updates SIGN, OVF. |
Comparison
| CMP Rd, Rs | 15 | SIGN <- sign(Rd - Rs), raw difference. OVF untouched. |
| CMP Rd, value | 16 | SIGN <- sign(Rd - immediate), raw difference. OVF untouched. |
Control flow
| JMP label | 17 | PC <- addr. |
| JEQ label | 18 | PC <- addr if SIGN = 0. |
| JNE label | 19 | PC <- addr if SIGN /= 0. |
| JLT label | 20 | PC <- addr if SIGN = -. |
| JGT label | 21 | PC <- addr if SIGN = +. |
| CALL label | 22 | Push return address, PC <- addr. |
| RET | 23 | Pop return address into PC. |
Stack
| PUSH Rs | 24 | mem[SP] <- Rs, SP -= 1. |
| POP Rd | 25 | SP += 1, Rd <- mem[SP]. |
Trit-wise logic
| LAND Rd, Rs | 32 | Rd <- trit-wise min(Rd, Rs). Updates SIGN, OVF. |
| LOR Rd, Rs | 33 | Rd <- trit-wise max(Rd, Rs). Updates SIGN, OVF. |
Input / output
| IN Rd | 34 | Rd <- next input value. Errors if the input buffer is empty. |
| OUT Rs | 35 | Output <- Rd. |