https://github.com/vasll/hassembler
Hack language assembler implementation
https://github.com/vasll/hassembler
assembler go golang hack-assembler hack-machine machine-language nand2tetris nand2tetris-assembler python python3
Last synced: 2 months ago
JSON representation
Hack language assembler implementation
- Host: GitHub
- URL: https://github.com/vasll/hassembler
- Owner: vasll
- License: mit
- Created: 2023-06-18T08:39:44.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-06-25T10:38:55.000Z (almost 2 years ago)
- Last Synced: 2025-01-21T20:33:06.463Z (4 months ago)
- Topics: assembler, go, golang, hack-assembler, hack-machine, machine-language, nand2tetris, nand2tetris-assembler, python, python3
- Language: Go
- Homepage:
- Size: 60.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hack-assembler
A hack machine language assembler made for the [nand2tetris](https://www.nand2tetris.org) course with python and Go.# Usage
```powershell
usage: hassembler [-h] file [outfile]positional arguments:
file path of the input .asm file
outfile path of the output .bin fileoptions:
-h, --help show this help message and exit
```# How does it work?
The hack platform from [nand2tetris](https://www.nand2tetris.org) has two basic A instructions and C instructions that need to be parsed into binary.\
The parsing of these instructions is done with different symbol tables consisting of a symbol and a binary value. Each line is read from the file and split into its various fields, then each field is parsed using the symbols table and finally written to the output file.
## A instructions
They always start with a '@' and change the value of the Address register, they can point to:
- A predefined symbol like a register `@R15, @R2, @THIS, @KBD, @SCREEN, ...`
- A label `@main_loop, ...`
- A memory address `@1254, @56, ...`
## C instructions
They can be of two types and perform computation on the ALU like adding, subtracting, anding, comparisons, flipping bits and so on:
- "dest=comp" `D=M, D=D-A, ...`
- "comp;jump" `0;JMP, D;JGT, ...`