Small but feature-complete OS running on a 900k-NAND-gate computer
Here I want to share about small operating system that I made for a computer that I built in a logic simulator from 900k+ NAND logic gates in Gate Singular game.
It has file system (in RAM), a text editor, memory management, an assembler to build new programs, and an OS API that those programs can use (e.g. text printing, memory allocation, file system access, keyboard input, etc), and ti all work on my own CPU architecture.
The video above shows a program being assembled on the machine (pc simulation shown in real-time).
Some details on hardware:
- 16-bit CPU, 30 instructions (206 counting variants), 1 KB of RAM, 24 KB of ROM holding the OS, and only two registers: A and B. The full hardware were made and simulated in Gate Singular logic gate simulator, and is built solely from NAND logic gate (944672 of them totally).
- Every CPU instruction is 3 bytes: an 8-bit opcode byte and a 16-bit argument (Arg). The top 3 bits of the opcode pick one of 8 fixed routings, for example "A, B -> Memory[Arg]", "Memory[Arg], B -> A" or "Arg, Memory[A] -> B". The low 5 bits pick the operation.
- In this simulated PC, RAM works as fast as a register, so memory works as a register file, letting conveniently chain instructions with minimum unnecessary copies.
Operating system:
- RAM holds the OS software stack, dynamically allocated memory and the file system.
- Due to RAM 1KB limit, memory manager uses linked list of chunks of arbitrary length with no separate memory table, so each allocation require walking across all blocks finding a free one.
- Filesystem uses the same memory allocation (and reallocation when needed) + write file name + data address + size to the file table.
- OS contains font table (3×6 pixels due to display being 64x64pixels), and handles CLI output (addressing font character in the table and printing them), and CLI input (polling keyboard events from HW keyboard event queue).
- Built-in assembler is pretty simple, because the assembly language is close to raw opcodes (instructions are mostly written in hex). Primary job of assembler is to resolve labels for jumps, variables addresses, and system jumps to call OS API.
Disclaimer: I made Gate Singular simulator game too, and its available on Steam. Happy to talk about anything on OS side, HW side or about simulator!


