A working emulator of the Soviet Setun 70 ternary computer (1970)
Project description
Setun 70 Emulator
A working emulator of the Soviet Setun 70 ternary computer (1970), reconstructed from archival documentation.
What Is This?
The Setun 70 was a balanced ternary computer developed at Moscow State University in 1970. It used:
- Balanced ternary numbers: digits are -1, 0, +1 (not 0, 1 like binary)
- POLIZ execution: Reverse Polish Notation with a two-stack architecture
- Syllable-based programs: 6-trit "trytes" instead of bytes
This emulator reconstructs the architecture from the original 1970 paper by Brusentsov, Zhogolev, and Maslov, recovered from the Russian Virtual Computer Museum and Bitsavers archives.
🌐 Try It Online
No installation required. Write POLIZ assembly and watch the ternary stack machine execute.
Installation
From PyPI
pip install setun70
From Source
git clone https://github.com/Zaneham/setun70-emulator.git
cd setun70-emulator
pip install -e .
Quick Start
Run the demos
python setun70.py
Run a program file
python setun70.py examples/hello.s70
python setun70.py examples/factorial.s70 --debug
Use as a library
from setun70 import Setun70, Setun70Assembler
source = """
LIT 10 ; Push 10
LIT 20 ; Push 20
ADD ; Add them
OUT ; Output result
HALT ; Stop
"""
asm = Setun70Assembler()
program = asm.assemble(source)
vm = Setun70()
vm.load_program(program)
vm.run()
# Output: OUT: 30 (ternary: 001010)
Demo Output
+==================================================================+
| SETUN 70 EMULATOR |
| Soviet Ternary Computer (1970) - Reconstructed |
+==================================================================+
DEMO: Balanced Ternary Arithmetic
-13 -> 000TTT -> -13
-5 -> 000T11 -> -5
0 -> 000000 -> 0
13 -> 000111 -> 13
224 -> 10T10T -> 224
DEMO: Arithmetic (3 + 4) x 5 = 35
OUT: 35 (ternary: 00110T)
DEMO: Factorial 5! = 120
OUT: 120 (ternary: 011110)
Why Balanced Ternary?
| Feature | Binary | Balanced Ternary |
|---|---|---|
| Digits | 0, 1 | -1, 0, +1 |
| Negation | Complex (two's complement) | Just flip all digits! |
| Rounding | Biased | Perfect (truncation = rounding) |
| Signed/unsigned | Two representations | One representation |
| Efficiency | Baseline | 5.4% better |
Decimal 13:
Binary: 001101 (6 bits)
Balanced Ternary: 000111 (6 trits, ~9.5 bits equivalent)
Negated: 000TTT = -13 (just flip!)
Assembly Language
Instructions
| Mnemonic | Stack Effect | Description |
|---|---|---|
LIT n |
-- n | Push literal value |
ADD |
a b -- a+b | Add |
SUB |
a b -- a-b | Subtract |
MUL |
a b -- a*b | Multiply |
DIV |
a b -- a/b | Divide |
DUP |
a -- a a | Duplicate |
DROP |
a -- | Remove top |
SWAP |
a b -- b a | Exchange |
NEG |
a -- -a | Negate |
OUT |
a -- | Print value |
HALT |
-- | Stop execution |
Example Program
; quadratic.s70 - Calculate x^2 + 2x + 1 where x = 5
LIT 5 ; x = 5
DUP ; x x
MUL ; x^2 = 25
LIT 5 ; x
LIT 2 ; 2
MUL ; 2x = 10
ADD ; 25 + 10 = 35
LIT 1 ; 1
ADD ; 35 + 1 = 36
OUT ; Output: 36
HALT
Architecture
Memory Model
- 27 pages (3^3) of 81 syllables (3^4) each
- 3 page registers for bank switching
- Total: 2,187 syllables (~20KB equivalent)
Syllable Format (6 trits)
Operation: [0 0 | type | opcode (3 trits)]
Address: [length | page_reg | offset (4 trits)]
Historical Context
The Setun 70 was developed at Moscow State University's Computing Center. Key facts:
- 1958: Original Setun built - world's only production ternary computer
- 1965: Production cancelled despite demand ("an ugly duckling")
- 1970: Setun 70 designed - research into optimal architectures
- 1970: Charles Moore independently creates Forth (similar stack model)
- 1995: Sun creates JVM (similar stack bytecode)
- 2025: This emulator reconstructed from archived papers
The DSSP (Dialogue System of Structured Programming) continues to emulate Setun 70 on binary computers to this day because the architecture's programming advantages remain compelling.
Project Structure
setun70-emulator/
├── setun70.py # Python emulator (~600 lines)
├── setun70_spec.md # Formal specification
├── README.md # This file
├── LICENSE # MIT License
├── pyproject.toml # Python package config
├── web/
│ └── index.html # Browser-based emulator (self-contained)
└── examples/
├── hello.s70 # Simple arithmetic
├── factorial.s70 # 5! = 120
└── quadratic.s70 # Polynomial evaluation
Contributing
Contributions welcome! Ideas:
- Add more instructions (comparisons, jumps)
- Implement the return stack for procedures
- Port programs from the 1968 Soviet program catalog
-
Create a web-based emulator✓ Done!
Deploying to GitHub Pages
To enable the web emulator at https://YOUR_USERNAME.github.io/setun70-emulator/web/:
- Go to your repo → Settings → Pages
- Under "Source", select Deploy from a branch
- Select main branch and / (root) folder
- Click Save
The web emulator will be live within a few minutes.
References
- Brusentsov, N.P., Zhogolev, E.A., Maslov, S.P. "General Characteristics of the Small Digital Machine 'Setun 70'" (1970)
- Russian Virtual Computer Museum: http://computer-museum.ru/english/setun.htm
- Bitsavers Soviet computing archive: http://bitsavers.org/pdf/ussr/
License
MIT License - see LICENSE
Part of The Ian Index - Reconstructing Lost Computing Architectures
Go find it for goodness sake.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file setun70-1.0.0.tar.gz.
File metadata
- Download URL: setun70-1.0.0.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64ee98a5b4f2f5c9c93fd84562a7f9d47f4c7844d8cdf831af779aa642eb51da
|
|
| MD5 |
46f5878ecf1951a866363b173670d699
|
|
| BLAKE2b-256 |
45d761423960ec6433ed17c00baefb418e7300420886569022ff91edb662a106
|
File details
Details for the file setun70-1.0.0-py3-none-any.whl.
File metadata
- Download URL: setun70-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
130d00e9c300c4df1c2021d5cf4a7a9555c83ab6ea853ca0628eac87c1987d64
|
|
| MD5 |
5a4fdca5513caabd43c62af98ab91dca
|
|
| BLAKE2b-256 |
37d9ad4e53271fefb9115855c66c237406cdc19ffa3f1a4e21ec130779e66316
|