The nand2tetris & Building a Modern Computer from First Principles

Hercules Lemke Merscher - Jan 5 '23 - - Dev Community

As programmers, we tend to work on top of many abstractions nowadays. But, have you ever got curious to know what is under the hood, and what it looks like?

Well, there’s a perfect textbook and course for that:

The Elements of Computing Systems: Building a Modern Computer From First Principles, 2nd edition

The Elements of Computing Systems: Building a Modern Computer From First Principles is the companion textbook of the nand2tetris project. The textbook, projects, and courses are by Noam Nisan and Simon Shocken.

A funny Nand gate playing Tetris (from the project’s website)

You can enroll in the course for free on Coursera, where it is divided into two parts. Part 1, focuses on the hardware, and part 2, focuses on the software. I digress below.

PS: on Coursera, the whole content of the course is available, however, you can’t submit the exercises to be evaluated, graded, and get the certificate unless you pay the subscription. The textbook has all the instructions to complete the exercises anyway.

 The proposition

The textbook’s and course's main proposition is to teach you the building blocks of a modern computer.

It starts with the most fundamental part, the CPU. You’re given just one simple logic gate, a Nand gate, and you will design other more complex logic gates based on that using a hardware design language.

Eventually, you going to get to the point where to perform some tasks you need to feed instructions to the CPU built from logic gates, and the machine language is then introduced, along with more details about the computer architecture, followed by the implementation of an assembler, the tool which is going to transform your (symbolic) machine language into binary instructions.

By finishing the assembler, part 1 is done, and the software-focused part starts.

The rest of the textbook and course will be then dedicated to the virtual machine, programming language, and operating system.

The virtual machine, called Hack, will be an intermediate language (often abbreviated as IL), bridging the gap between the Jack programming language, the high-level language proposed, and the machine language.

A Jack compiler is then built to translate Jack's code into the Hack instructions.

A frugal operating system abstraction is introduced while developing the compiler, and the last project will take care of exposing the underlying complexities of the operating systems, in order to run programs where performance, efficiency, and interfacing with devices matter, in order to run complex programs, such as games - did I hear Tetris? - wrapping up the whole experience.

My considerations

If you never read or studied computer architecture before, my personal recommendation is to read another book first: Code: The Hidden Language of Computer Hardware and Software, by Charles Petzold.

Code: The Hidden Language of Computer Hardware and Software

It has a more approachable introduction to the topic, IMHO, with some historical background, which makes it even more interesting as a first read. It has no practice involved.

Feel free to jump straight to the nand2tetris course if you feel like getting your hands dirty.

From my perspective, some prerequisites need to be met to enjoy the reading and the practice that comes with it, and avoid frustrations:

  1. I would not recommend this textbook and course if you’re not acquainted with programming. You do not need to be a seasoned programmer though.
  2. The basics of Big O notation and algorithm analysis are used in the last exercises, and some previous familiarity will help you not get confused with the terminology, and set the right expectations regarding efficiency and performance.
  3. Reserve at least 6 to 8h a week to read each chapter and work on the projects.
  4. Be curious!

 My journey

My personal experience with it has been very positive.

I both read the book and followed the course on Coursera. It’s useful to do both because there are so many details to be covered, and the perspective of reading the textbook might be different than watching the professors explain. IMHO, one complements the other, and both should be taken into consideration.

Also, I was invited to a book club. It’s so helpful and fun to have someone to talk to about the hurdles and celebrate the small victories. I definitely recommend starting a book/course club, if you have this option.

I started it in February 2022 and the first 4 to 5 chapters were concise enough to allow me to complete 1 chapter/project per week. Then it started requiring more time, but that’s ok, take your time and it will be fun anyways.

I won’t lie. For me, it has been full of back and forths, but don’t get me wrong, it’s not the course’s fault. The content is dense and challenging. Sometimes life gets in the way, and you need to give it a break. However, the pleasure of uncovering new secrets and overcoming the small challenges presented in every chapter makes you thirsty for more.

I recognize that if I hadn’t paused it for more than a week a few times, my experience would be optimal. Anyway, it’s not a big deal if you have to, you will just need to refresh your mind on the previous chapter a little bit and you’ll be ready to go, as I did.

Conclusion

I finished reading it, and I’m about to complete the last exercises yet, but I couldn’t hold myself up sharing about it. I enjoyed it a lot, and I gave it 5 stars on Goodreads!

It’s one such book that can change your perspective and broaden your horizon as a programmer! Unless you have studied all these topics at the university. In this case, you probably don’t need it, but not everybody has the chance to work on a project like that from cover to cover, or should I say, from nand to tetris.

HIGHLY RECOMMENDED!

Thumbs up and ok hand


If you liked this post, consider subscribing to my newsletter Bit Maybe Wise.

You can also follow me on Twitter and Mastodon.


Photo by Pablo Zuchero on Unsplash

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .