Skip to content

Hackasm is the assembler which translates Hack assembly to Hack machine code. Built for project 06 of Nand2Tetris.

Notifications You must be signed in to change notification settings

dphogit/Hackasm

Repository files navigation

Hackasm: Assembler for Nand2Tetris Hack Machine

Hackasm is an assembler developed as part of Nand2Tetris, which translates programs written in Hack assembly language into Hack binary code.

The name Hackasm is a play on words because it combines the Hack machine, assembly (ASM) and another word to describe when a person feels a certain pleasurable sensation...

Sample Programs

Sample Hack assembly programs which are used for the Nand2Tetris project are provided in the Programs folder in the E2E test project.

Development

Note

This project is an educational exercise with the goal to be able to translate all the assembly programs provided Nand2Tetris. Therefore, committing time to robustness and production-readiness is not as prioritised, though I have followed practices that have helped me implement the initial assembler in parts as well as keep in mind future development. i.e. automated testing with CI, and separating the assembly passes into different classes.

The assembler is built using C# and is a Console Project.

# Run
dotnet run [FILE]

# Test
dotnet test

There are three stages to the assembly process, which the class names in the project should explain themselves:

  1. Preprocessing: Removes unneccessary parts that are not required for machine code translation. This includes comments, blank lines and leading/trailing whitespace.
  2. Label Symbol Resolving: Label symbols are pseudo-instructions which bind to the address of the next instruction in the program. Because label symbols can appear anywhere in the program, especially in previous instructions before the label symbol itself is declared, a separate pass is required to figure out which address these labels bind to. This allows the subsequent translation layer to be able to correctly translate the address when the label is used in another instruction such as a jump or A-Instruction.
  3. Translation: The actual conversion from assembly to Hack machine code.

These steps along with the file handling are all driven by the project's entrypoint in Program.cs.

About

Hackasm is the assembler which translates Hack assembly to Hack machine code. Built for project 06 of Nand2Tetris.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published