Skip to content

Assembler, VM-Translater, Compiler and OS of HackMachine (nand-to-tetris) written in go

Notifications You must be signed in to change notification settings

Keisn1/nand-to-tetris-in-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Readme

Nand to Tetris

https://www.nand2tetris.org/

“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.

Assembler

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 into binary machine code.

This assembler plays a significant role in the overall process of creating a functioning computer system from scratch.

I have been diligently working on implementing the assembler in Go (Golang), a versatile programming language known for its efficiency and simplicity. This task has allowed me to deepen my understanding of low-level programming concepts and strengthen my skills in software development.

Virtual Machine Translator

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.

To come

Game written in Hack

Compiler for the Hack Language (in GO)

OS written in Hack

Implementation

Test driven

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.

Assembler

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.

VM Translator

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.

About

Assembler, VM-Translater, Compiler and OS of HackMachine (nand-to-tetris) written in go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published