Build a Modern Computer from First Principles
Pavel Tcholakov
I love building things | Cloud, distributed systems, & DBs | Engineer @ restate.dev
I recently completed part one of the nand2tetris course on Coursera, aka “Build a Modern Computer from First Principles: From Nand to Tetris”. I discovered The Elements of Computing Systems book some time ago but it was languishing somewhere not very near the top of my reading / to-do list ever since, with a vague notion of “this is something I would really love to do one day”. When I saw a guided 6-week course pop up in my Coursera recommendations, it was just the nudge I needed to finally pick it up. I signed up on the spot.
The first part of the course covers building a functional computer starting with nothing but Nand gates and Flip-Flops – the semiconductor nuts and bolts of modern electronics. Don’t worry though, there is absolutely no soldering required to complete the weekly assignments! The circuits and chips are developed using a simple Hardware Description Language, and verified using a supplied simulator. There are some brief asides about the underlying physics and the electronic engineering that goes into implementing the basic building blocks, but this is a course about computing. All you need is a simple text editor, and a bit of time. (The provided tooling is built in Java and works on PC/Mac/Linux.) The course concludes with the development of a simple assembler which is capable of translating (relatively) human-readable low level instructions into machine code.
The brilliance of the couse is in the gentle yet steady ramp up. The computer architecture is carefully designed to be easy to implement yet illustrative of the powerful principles underpinning any modern smart device, PC, or server. Week after week, additional abstractions are layered on top of previous work. The course materials include test scripts which will exercise the piece you are busy developing – helpful to know with confidence when you are done with any given task. These work much like an automated test suite and are a key part of being able to rapidly move up the levels of abstraction.
If you are a builder at heart, there is the sheer joy of developing this all yourself and seeing how the pieces fit and interact. But more than that, for those of us working much higher up the software stack, it’s the development of mechanical sympathy for what lies beneath the high level components we focus on the majority of the time. This is the notion, widely credited to Sir Jackie Stewart, that racing drivers should have a reasonable understanding of their cars’ mechanical engineering and the forces at play in order to be able to efficiently extract the best results over the duration of a race meeting. Martin Thompson has been popularising this same idea in the software engineering context for some time now. For myself, I feel this is the biggest benefit of having completed the projects.
// Compute R0 = 2 + 3
@2
D=A
@3
D=D+A
@0
M=D
I would highly recommend the course and book to any aspiring software builder or computing enthusiast. I suspect it would be a great project to tackle with kids too – with a bit of guidance it should be easily doable for almost anyone. There is an upcoming part two of this course, which will cover the second half of the book – the development of a stack-based virtual machine and a compiler for a high-level, object-oriented language targeting it. I cannot wait!