Skip to content

devvolve/project-6

Repository files navigation

Project 6: Hack Assembler

Overview

This project implements an assembler for the Hack computer from "The Elements of Computing Systems" (Nand2Tetris). The assembler translates Hack assembly language into 16-bit binary code, handling both symbol-less and symbol-rich programs using a two-pass process.

Project Structure

  • assembler.py: Main Python script that implements the assembler.
  • Parser Module: Reads and parses the input .asm file, removing comments and whitespace.
  • Code Module: Contains lookup tables and functions for converting assembly mnemonics (comp, dest, jump) into binary codes.
  • SymbolTable Module: Manages symbols (labels and variables) and maps them to their corresponding addresses.
  • test_code.py: Unit tests for verifying that the Code module functions correctly.

How to Run

  1. Assembly Process:
    To assemble a Hack assembly file, run:

    python assembler.py <inputfile.asm> <outputfile.hack>

    For example:

    python assembler.py Add.asm Add.hack
  2. Unit Testing:
    Run the unit tests using:

    python -m unittest test_code.py

Testing and Verification

  • Comparison Testing:
    I verified that the output .hack files match exactly with the reference output generated by the supplied Nand2Tetris assembler using the compare feature.

  • CPU Emulator Testing:
    I loaded the generated .hack files into the Hack CPU Emulator to confirm that the programs execute correctly on the simulated hardware.

GitHub Repository

You can view the complete source code, tests, and documentation in this repository.

Credits

This project is based on the work described in The Elements of Computing Systems by Noam Nisan and Shimon Schocken, MIT Press. The project is part of the Nand2Tetris course curriculum.

About

**Project Description:** A Python-based assembler that translates Hack assembly language into 16-bit binary code using a two-pass process to handle both symbol-less and symbolic instructions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors