Complete enough that a second, independent emulator could be built from this page alone. Everything here is what the playground actually executes.
Number system
A trit holds one of three values, written - for -1, 0 for 0, and + for +1. Trits are written most significant first, so the digit at position i from the right carries weight 3i.
Zero is all-zero trits and has exactly one representation.
Negation is trit-wise inversion; there is no sign trit and no two's-complement rule.
The sign of a value is the sign of its most significant non-zero trit.
Arithmetic that leaves the word range wraps within 729 states and sets the overflow flag.
Decimal
Balanced ternary word
1
00000+
-1
00000-
8
000+0-
-8
000-0+
121
0+++++
364
++++++
-364
------
word dial
set each switch to -0+
243
81
27
9
3
1
reads000----9 -3 -1 =-13
Machine word
trits per word6 (one "tryte")
distinct values729
integer range-364 .. 364
register width6 trits
memory unit1 word
instruction width3 words (18 trits)
overflowwrap-around, OVF flag set
Registers
8 general-purpose registers plus three special registers. R0 is hardwired to zero: writes to it are discarded.
R0constant 0, immutable
R1 .. R7general purpose, reset to 0
PCprogram counter, reset to 0, advances by 3
SPstack pointer, reset to 364, grows downward
FLAGSSIGN (-, 0, +), OVF, HALT
SIGN is a single trit rather than a set of boolean condition bits: arithmetic sets it to the sign of the result, and CMP sets it to the sign of the difference. Conditional branches read it directly — JLT on -, JEQ on 0, JGT on +.
Memory
size729 words
addresses-364 .. 364 (balanced, like any word)
reset stateevery word is 0
program originaddress 0, growing upward
stackfrom 364 downward
out-of-range accessexecution error, machine halts
Instruction encoding
Fixed width: every instruction is exactly 3 words.
Word
Contents
PC + 0
opcode
PC + 1
operand A — register number, immediate, or address
PC + 2
operand B — register number, immediate, or address
The opcode fixes the operand kinds, so ADD Rd, Rs and ADD Rd, value are separate opcodes. Unused operand words are 0. An opcode with no definition raises an invalid-instruction error and halts the machine.
Assembly syntax
comment; to end of line
labelNAME: at the start of a line
registerR0 .. R7
decimal literal42, -17
ternary literal+0- or 0t+0-
memory reference[100], [LABEL], [R2]
The assembler reports unknown instructions, invalid registers, malformed literals, wrong operand counts, invalid operand types, duplicate labels, unresolved labels, and out-of-range values — each with its source line.