/hack-assembler-python

hack-assembler for nand2tetris

Primary LanguageHack

Hack Assembler in Python

GitHub last commit GitHub code size in bytes

This repository contains a Python implementation of the Hack computer's assembler, as described in Chapter 6 of the Nand to Tetris course. With this assembler, you can translate Hack Assembly Language code into Hack Machine Language code.

Prerequisites

  • Python 3.11 or higher is required to run this assembler. You can download the latest version of Python from the official Python website.

Installation

To use this assembler, you can clone this repository:

git clone https://github.com/cuspymd/hack-assembler-python.git
cd hack-assembler-python

Usage

You can assemble Hack Assembly Language code using the following command:

python -m hack_assembler.assembler input.asm

This will generate an input.hack file in the same directory as your input assembly code (input.asm).

Example

Suppose you have the following input.asm file:

// input.asm
@2
D=A
@3
D=D+A
@0
M=D

Running the assembler as shown above will create an input.hack file with the corresponding Hack Machine Language code.