Jessica Herring's profile

Hack Computer Build

This project involved building a computer from scratch using the Nand2Tetris guide. It centered on learning fundamental principles of computer architecture and gaining hands-on experience in the construction of a computer. This project was split into two distinct sections-- hardware and software. The hardware components consisted of building rudimentary logic gates alongside larger chips such as the ALU, CPU, memory, and computer. The software components included building an assembler, virtual machine, compiler, and an operating system. It provided practical insight into the inner workings of a computer and the 12-step project ended with a fully functional Hack computer capable of running programs written in the Jack programming language.
Rudimentary chips-- 'and', 'or', 'not, and 'xor'-- were built strictly using Nand gates (the most primitive chip) and each other. For example, the 'not' chip used only a single Nand, while 'and' uses both a Nand and a 'not'.
From the rudimentary chips, more complex multiplexers and demultiplexers were built. 
These chips were more intensive to design and built off the previously built chips. The register is typically responsible for instruction and address memory. The ALU is responsible for simple addition, subtraction, multiplication, division, and logic operations that happen at the hardware level. Finally, the PC is a 16-bit program counter. 
These were the final chips and concluded the hardware section. The CPU was the hardest chip to design and problem solve. It is responsible for carrying out commands and instructions. The computer is the highest level chips and utilizes the functionality of every chip built up to this point. 
*Note: not all chips that were built are shown above, however, those shown are representative of the important chips and the work done during the hardware section of the project 
MACHINE LANGUAGE
Machine language plays a crucial role in computer functionality as it enables low-level programming to interface directly with computer hardware. By utilizing machine language, software inputs gain direct control over the chips developed in previous project stages. The Hack machine language employs a data register and an address register, which, along with a processor, facilitate memory manipulation within the RAM. The address register (A) serves the dual purpose of addressing and accessing data from the instruction memory, while the data register (D) is responsible for storing 16-bit values. The primary objective of the project was to gain a comprehensive understanding of machine language, achieved through the creation of programs for multiplication and input/output (I/O) handling (seen in the video above). Writing these programs provided valuable insights into leveraging the A and D registers for effective memory manipulation and storage.
ASSEMBLER
An assembler was built to translate symbolic machine language instructions to 16-digit binary instructions. For example, the machine instruction M=0 can also be written 1110 1010 1000 1000. The symbolic value is intuitive to humans while the binary value can be implemented directly onto the hardware of the Hack computer.
VIRTUAL MACHINE
A Virtual Machine (VM) translator was built to convert VM language code into equivalent assembly language code. The translator accommodates both single files and directories containing multiple VM code files, and it enables the translation of arithmetic-logical, branching, and function commands. Its output produces well-organized and human-readable assembly code, compatible with the Hack machine architecture. The translation process involves a multi-pass approach: the first pass reads and stores all lines from the file or directory, the second pass removes comments and whitespace, and parses the remaining lines into commands and parameters. Finally, in the third pass, the translate method receives the parsed commands and parameters, converting them into assembly instructions.​​​​​​​
JACK PROGRAMMING
A video game was designed in the Jack programming language to begin exploring and becoming familiar with the Jack language. We made an infinite runner game with a simple game design– only consisting of two images: a runner and a spike. The runner moved strictly vertically, along the y-axis, and the spike moved strictly horizontally, along the x-axis. As the spike approaches the runner, the runner can choose to jump over the spike, by pressing the space bar, or to stand still. A score bar exists at the top of the screen, and if the player successfully jumps over the spike, the score bar grows. If the game is played long enough, the bar would stretch across the screen. The game halts once the bar reaches the other side of the screen or the player is hit by the spike.
COMPILER
A Java compiler was developed to convert Jack files into VM code, which can be executed using a virtual machine. The process involved syntax analysis, carried out by a tokenizer and parser, and concluded with code generation. The tokenizer divided the program's text into tokens, categorized as keywords, symbols, integer constants, string constants, and identifiers. On the other hand, the parser utilized the tokenizer's output to analyze the file's syntactic structure, generating an XML file with tagged tokens. The parser was then transformed into a code generator to produce VM code instead of XML. This required mapping each grammar component to its equivalent VM code, making it the most challenging part of the project.
OPERATING SYSTEM
The operating system (OS) was the final piece of this project. It involved developing the various essential components that are process management, memory allocation,  screen display, math operations, and I/O handling. The goal is to design an operating system that provides an interface between the hardware and higher-level software, enabling efficient resource management and facilitating user interactions. The images and video shown above are representative of the testing process for different OS features.  
Hack Computer Build
Published:

Owner

Hack Computer Build

Published: