We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.
4 tridigits, 169 tridigytes
4 tridigits, 169 tridigytes is yet another programming language designed by PSTF. It is inspired by 2 undigits, 121 undigytes by Mutasimos which is inspired by 7 heptits, 49 heptytes by PSTF which is inspired by 3 pentits, 25 pentytes by Mutasimos.
Terminology
- Tridigit: A single base-13 digit.
- Tridigyte (TY): A group of 2 tridigits.
- Word: A group of 2 TYs.
- Memory consists of 169 TY, addressed linearly from 00 to CC (decimal 0 … 168).
Registers
There are 4 general-purpose word-wide registers, notated with A, SP, PC and FS.
At the beginning, the SP points to the highest memory location, that is CC13.
FS consists of "ZF" and "NF" for zero and negative.
ALU supports four arithmetic operations(division are seperated into integer division and modulo), along with increment and decrement.
Arithmetic is modulo 13⁴; signed interpretation:
A is negative if its most significant trit ≥ 7 (i.e. A ≥ 7CCC).
Instruction size: 2 TY (4 trits), aligned on even‑numbered TY addresses. PC advances by 2 after each instruction fetch.
Instruction Set
All instructions use the 2‑tridigit opcode + 2‑tridigit operand format:
[ opcode (2 trits) ] [ operand (2 trits) ]
The operand is a TY address (00 … CC) for memory ops, or ignored for unary I/O.
================COMMAND SHEET================ 00. NOP : No operation. 01. LDA addr: Load a word from addr to addr+1 to A. 02. STA addr: Store the highest two tridigits of A to addr while lowest two ones to addr+1. 03. ADD addr: A ← A + word(addr). 04. SUB addr: A ← A - word(addr). 05. JMP addr: Jump unconditionally. 06. JEQ addr: Jump if ZF = 1. 07. JLT addr: Jump if NF = 1. 08. INC : A++. 09. DEC : A--. 0a. OUT : Output A as tridecimal number. 0b. IN : Input a tridecimal number to A. 0c. HLT : Halt. 10. PUTC : Output A as a character. Codepage is same as ASCII while the value greater than 127 are ignored or printed as question mark. 11. GETC : Input a character to A. 12. MUL addr: A ← A * word(addr). 13. DIV addr: A ← A / word(addr), results in integer. 14. MOD addr: A ← A mod word(addr). 15. JNE addr: Jump if ZF = 0. 16. JGE addr: Jump if NF = 0. 17. JLE addr: Jump if either ZF or NF is 1. 18. JGT addr: Jump if both ZF and NF is 0. 19 ~ cc: Reserved.
Addressing and Self-Modification
Direct addressing is the only built‑in mode, but self‑modifying code provides full indirect addressing, making the ISA universal.
Indirect load via self‑modification:
LDA TARGET_ADDR ; A holds the desired address (0..CC)
STA PATCH+1 ; write low TY of A into operand field of instruction below
PATCH:
LDA 00 ; this instruction is patched to LDA <target>
... ; now A contains word from target address
Because we can compute addresses, store them, and patch operands, we can implement arbitrary indirect reads/writes, conditionals, and loops. Combined with arithmetic and branching, this yields a Turing‑complete model (provided memory is conceptually unbounded).
I/O Details
Numeric I/O (IN/OUT):
- Input: reads a token consisting of base‑13 digits (0‑9A‑C) until whitespace; parses it into a 4‑tridigit word (leading zeroes allowed).
- Output: prints A as a base‑13 number without leading zeroes (zero prints as 0).
Character I/O (GETC/PUTC):
- Input: reads a single character from stdin, stores its ASCII value (0‑127) in A.
- Output: converts (A mod 169) to an ASCII character and prints it. Values > 127 are printed as ? (or ignored – implementation defined).
Assembler Syntax & Example
- Comments start with ;.
- Labels: label: (placed on a separate line before an instruction).
- Directives: .ORG <addr> sets the starting TY address for subsequent code/data.
- Constants: base‑13 literals (e.g. A3, 1C0, 00) or ASCII using single quotes (e.g. 'X' gives ASCII code).
Examples
Cat Program
.ORG 00
LOOP:
INCHR ; read a char into A
JZ DONE ; if EOF (0) jump to halt
OUTC ; echo the character
JMP LOOP
DONE:
HLT