Skip to content

Latest commit

 

History

History
31 lines (27 loc) · 1.25 KB

README.md

File metadata and controls

31 lines (27 loc) · 1.25 KB

nand2tetris-assembler

Project 6 of the Nand to Tetris course.

  • Translates the "Hack" assembly language into its equivalent binary representation.
  • Written in Python.
  • See the examples folder for example input/outputs.

Program Structure

  • parser.py reads and each assembly command in the program, breaking it up into its symbols.
  • code.py translates the assembly mnemonics into binary codes
  • symboltable.py keeps track of symbol labels (variables) and their corresponding numeric addresses.
  • assembler.py uses the previous modules to translate files

Usage

Use assembler.py to generate .hack files (binaries) from .asm files (assembly code)

python3 assembler.py <.asm file>
Ex: python3 assembler.py examples/add/Add.asm

Use comparer.py to compare this assembler's output and the course's assembler's output.

python3 comparer.py <file1> <file2>
Ex: python3 comparer.py examples/add/Add.cack examples/add/Add.hack

Note that assembler.py generates .cack files to differentiate between this assembler's output and the course's assembler's output.

The output file extension can be changed in assembler.py.