!!! All the Material (lectureNotes, instructions, tutorials etc.) was provided from the Team at NandToTetris and can be found on their webpage https://www.nand2tetris.org/ !!!
I am extremely thankful to all of the persons behind FromNandToTetris for their great work and for making this amazing course publicly available for everyone to study. And I don’t claim any credit other than for completing the projects myself. I re-share these materials here only for educational purposes and making this repo more readable and understandble.
“Nand to Tetris” is a project-based course that teaches computer science students how to build a modern computer system from first principles.
Participants start by creating basic logic gates using the Nand gate and gradually progress to designing and implementing a fully functional computer system, including a CPU and an operating system.
The course covers various topics in computer architecture, software development, and digital design, providing a hands-on understanding of how computers work from the ground up.
To each of the projects you will find additional explanations inside the corresponding directory.
We are building the Basic Logic Gates:
Not
,Not16
,Or
,Or16
,Or8Way
,And
,And16
,Xor
,Mux
,Mux16
,Mux4Way16
,Mux8Way16
,DMux
,DMux4Way
,DMux8Way
We are doing some math with the Gates that we just built, finally building our ALU
HalfAdder
,FullAdder
,Inc16
,Add16
,ALU
Our Chips discover the notion of time and there they will be able to remember (at least the state that they have been in the last second).
We are building:
Bit
,PC
,RAM8
,RAM64
,Register
,RAM512
,RAM4K
,RAM16K
We are discovering the architecture of the Hack Computer by getting to know its instruction set and the corresponding Machine Language.
We are writing first programs for our computer:
add, fill, flip, for_loop_with_pointer, keyboard, mult, screen, signum, sum1Ton
Now we are getting to know the actual intracacies of how to put together Chips to a Computer.
We talk about Fetch and Execute cycles and the actual architecture of the Hack Computer.
The project is to actually build the computer in Hardware Description Language.
In Week 6 of the “Nand to Tetris” course, participants work on building an assembler, which is a crucial component that translates symbolic assembly language (Hack Machine language) into binary machine code (Hack instructions).
This assembler plays a significant role in the overall process of creating a functioning computer system from scratch.
In Week 7 and 8 of the “Nand to Tetris” course, students typically focus on implementing a virtual machine (VM) and a compiler.
During these weeks, participants learn how to design and build a virtual machine that executes a stack-based language and develop a high-level language compiler that translates a high-level language into the VM’s low-level language.
This part of the course delves into the principles of programming languages and compiler construction, providing a comprehensive understanding of software development processes.
make install-assembler
hack_assembler Max.asm
or
hack_assembler --out new.hack Max.asm
For all of the software projects built in go, I adopted a Test-Driven Development (TDD) approach to refine my implementation.
Given the nature of the course and the supplied material it was easy defining comprehensive test cases to validate desired behavior first (translation into MachineCode/assembly; correctly parsing command lines ).
Before moving on to the next case, I ensured that each unit of code functioned correctly. This iterative testing methodology helped me identify and address potential issues early in the development cycle and allowed me to apply refactoring at each step.
For both, the Assembler and the VM translator, propose a 2 tier design of a Parser and CodeWriter.
For the assembler I finally didn’t follow that advice and implemented the Assembler in one object. The assemble process consists of two stages. A first pass to get all Labels and a second one to actually translate assembly to machine code instructions.
The VM Translator consists of a Parser and a CodeWriter where I basically follow the proposed implementation design of the code authors.
For the VM translator, I employed Go’s text/template package to streamline the generation of code templates, making the translation process smoother and more structured.
In implementing the VM translator in Go, I leveraged the power of the language by making use of the “embed” feature, which allowed me to efficiently include the necessary VM translation files directly into the executable binary.