I Wanted to Make a Game From Scratch, So I Started by Building the Computer
My journey through Parts 1 & 2 of the Nand2Tetris course, where I developed a 16-bit computer, assembler, VM translator, compiler, and my own game.
Published: Tue Aug 12 2025“If you wish to make an apple pie from scratch, you must first invent the universe. - Carl Sagan” Link↗
This quote is a good reminder of how deeply connected things are, and how “from scratch” can mean starting far earlier than you might expect.
The Nand2Tetris course explores this idea in the context of computers, beginning with the simplest logic gate and ending with a working system that can run your own programs.
If you’re unfamiliar with it, Nand2Tetris along with its companion book “The Elements of Computing Systems: Building a Modern Computer from First Principles” guides you through building a computer from the ground up, in two parts.
Here is the big picture and the course starts us at the bottom with the NAND gate, working through abstraction by abstraction until we end up at human thought.
Here is a video about part one from the course.
Part 1: Hardware
- NAND Gate: The foundation of all other logic gates.
- Logic Gates: AND, OR, NOT, XOR, Multiplexers, and more, all built using only NAND gates.
- 16-bit ALU (Arithmetic Logic Unit): The “brain” of the computer, capable of performing arithmetic and logic operations.
- Registers and Memory (RAM): From basic flip-flops to a 16-bit RAM capable of storing data and instructions.
- 16-bit CPU: A central processing unit designed to execute machine instructions.
- Hack Computer: A fully functional 16-bit computer capable of running assembly code using all the parts above.
- Hack Assembler: Translates assembly code written for the Hack computer into machine code that the Hack hardware platform can execute.
By the end of Part 1, I had a simulator ready computer capable of running programs in Hack Assembly. Including of course, Tetris.
Here’s an example of HDL used to make chips and gates like the HalfAdder. This is similar to Verilog, a professional tool to make modern chips we use in our phones, computer, and other devices.
/**
* Computes the sum of two bits.
*/
CHIP HalfAdder {
IN a, b;
OUT sum, carry;
PARTS:
Xor(a=a, b=b, out=sum);
And(a=a, b=b, out=carry);
}
Part 2: Software
- Virtual Machine Translator: Translates stack-based virtual machine code into Hack assembly.
- Jack Compiler: A compiler for the high-level Jack programming language, capable of translating Jack programs into VM code.
- Operating System: Built essential libraries and functions for drawing to the screen, allocating memory, math, etc.
I implemented my Jack Compiler in Java (source), then wrote my VM Translator in Go (source) as a way to learn the language. With the Hack assembly generated, I used my Hack Assembler (source) written in Rust to produce the final machine code.
Bringing It All Together
With the toolchain above complete I can run my own game I created in Jack. Bat Dash, a simple dash game with animated sprites on the 512x256 1-bit pixel screen of the Hack computer. While this game is very simple, it was somewhat complex to implement on such a basic computer. The RNG logic was created from scratch and could use some improvements, but I’m satisfied with how the sprite animations turned out for the playable bat and the obstacles it dodges.
I went through both parts 1 and 2 on Coursera. If you’ve ever been curious about building a computer from the ground up, I can’t recommend the experience enough. It’s equal parts challenging, surprising, and fun.