DEV Community

Lucas
Lucas

Posted on

I built an 8-bit CPU from NAND gates, and it runs Tetris

I just finished a side project I’m pretty proud of: a complete 8-bit CPU built from a single building block, the NAND gate.

How it’s built

From NAND gates I made the basic logic gates, then adders, registers and memory, all the way up to a full CPU. Everything runs in Digital Logic Sim, a free logic simulator, so there’s no hardware to buy.

8-bit ALU (numbers from 0 to 255)
16-bit addressing, so 64K of RAM
800 kHz clock
A small OS running Snake, Breakout, Flappy Bird and Tetris, playable live with the keyboard
The software side

Writing programs in binary by hand got painful very quickly. So I wrote my own programming language and a compiler that outputs the program memory contents directly.

What’s next

I’m thinking about a step-by-step tutorial series on building your own CPU from the NAND gate. Would that interest you? Let me know in the comments!

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.