Introduction

This first post will attempt to be a summary of what I have already done and learned while doing the first half of the nand2tetris lesson on Coursera. Following the advice on the FAQ from r/LearnProgramming redirecting to a nice ressource on Github (the Open Source Society University course), I decided to start from the basics to be sure I didn’t miss important basic knowledge.

Learning the basic architecture of a computer is also something I really wanted to do, so when I saw it was the first part of the curriculum I was only more excited to get my hands on this ! Also, this is a great occation to try developping small applications from scratch in C, which is the language I’d like to learn the most.

Objective

This first part was focused on building the hardware architecture from the bottom up. Starting from the NAND gate (supposedly made of 2 transistors) up to building an assembler that translates specified assembly code into binary instruction for the built CPU implementation. As stated in the README of the nand2tetris project I made to share me developments, we also were able to count the number of transistors needed to make a working ALU, and then a working CPU. I mean, I’m still not sure how multiple cores are actually implemented, but pretty much everything else was covered.

Building the Assembler

The last project of the first part of the course is to build an Assembler. I did the project in C since it’s the first language I tried to learn, and also a language that would make me wonder how to handle memory properly while implementing the necessary hash table for symbols, and queue for the instruction list.

The hash table is implemented using an array of linked lists and the instruction queue is also implemented as a linked list and those implementations proved to be a little redundant. Proper inheritance between classes will be tried later to reduce the redundant lines.

The End ?

All those small issues were eventually fought, and working version of the assembler is now on the repo of the course. A lot of mistakes were made, but hopefully I learnt from them all (spoiler : I did not) and the next program will be perfect (spoiler : the next program is a translator from virtual machine code to Assembly, and it is not perfect).

Next adventures concern the second part of the course, where hopefully, I’ll get to understand Operating systems, two-tier compilation and other architectural facts from computers.

Stay safe, Gerry