detrytus
A balanced-ternary computer: an instruction set, and an assembler, emulator and debugger that run it on your own machine.
detrytus asks what a ternary computer would look like if it had kept evolving alongside binary ones for another fifty years. It is in the line of the Setun (1958) and Setun-70 (1970), the ternary computers built at Moscow State University, but it is not a Setun emulator and cannot run Setun programs. It shares their number system, balanced ternary, and the idea that a machine built on it can be simpler than a binary one. Everything else is a modern design.
The name is detritus with a tryte in it.
| Setun (1958) and Setun-70 (1970) | detrytus | |
|---|---|---|
| Word | 18 trits (Setun), with 9-trit short words | 27 trits; a tryte is 9 trits |
| Design | accumulator machine (Setun); two-stack machine (Setun-70) | load/store with 27 registers, like RISC-V or ARM |
| Hardware | ferrite cores and diodes | a specification and a software emulator |
| For an operating system | none in the modern sense | privilege rings, traps, virtual memory, a timer, interrupts, up to 729 cores |
Ternary, not binary in disguise
Where ternary lets a feature be simpler than its binary equivalent, the design takes the simpler form:
- A comparison gives a trit (−1, 0 or +1), and one instruction jumps three ways on it, so a binary search needs one compare per step, not two.
- Negating a number and flipping its trits are the same instruction.
- Multiplying or dividing by 3 is a shift.
- One instruction can compute any of the 19,683 possible functions of two trits.
- Memory pages, words and tables are centred on their addresses, so splitting an address into page and offset is just cutting it into two groups of trits.
- The sign of a page number says what it is: positive pages are memory, negative ones are devices.
- Floating point is ternary too, with every result rounded once.
What the emulator does
The detrytus command assembles, runs and debugs programs. It has the
whole instruction set, three privilege levels, paged virtual memory, many
cores, a console, a disk, an Ethernet network device that can reach the
internet through your computer, and a compiler that turns hot code into
your computer's own instructions as it runs. It also compiles Trice, the
machine's own C-like language, and translates no_std Rust programs.
Try it
You need a Rust toolchain, 1.97 or later.
git clone https://github.com/sgaduuw/detrytus
cd detrytus
cargo install --path rust/cli
detrytus run examples/hello.s
detrytus debug examples/bsearch.s steps through a program instead, and
detrytus on its own lists every option.
Read more
The detrytus repository has the full
documentation, starting with its
README. The instruction set is
specified in
docs/isa.md,
and the reasons behind the design are in
CONTEXT.md.
To see the machine do something real, boot trylobite, the operating system written for it.