An assembler and disassembler for the low-level language hack assembly, which will convert hack assembly(.asm
) files to machine language (.hack
), and machine language files to hack assembly.
This program takes hack assembly (or .asm
) files and assembles them into machine language (.hack
), A.K.A, binary. I used the file extension .hack
to represent machine language code. Not to be confused with the programming language hack, the .hack
files in my program only consist of binary, or 1's and 0's.
The files you see that end with .asm
or .hack
are there pureley for testing. You can test it yourself to see the assembler/disassembler in action. You can also create your own files if you so wish. Assembling test.asm
will result in the test.hack
file and vice versa. The same is true for programTest.asm
and programTest.hack
. Of course, if you don't delete any of these, nothing will change when you run it through the program, as both the .hack
and .asm
files already exist, so no new files will be created.
https://www.youtube.com/watch?v=sT9SZdZqSJE
The Hack Assembly Language consists of 3 types of instructions. It allows us to declare symbols with a single symbol declaration. Hack assembly ignores whitespace and you can write comments with //
.
- A-Instruction: Addressing instructions, used with a preceding
@
- C-Instruction: Computation instructions, used with either
=
or;
- L-Instruction: Labels (Symbols) declaration instructions, used with
(symbol)
- A: Address Register
- D: Data Register
- M: Refers to the register in Main Memory whose address is currently stored in A
- R0-R15: Addresses of 16 RAM Registers, mapped from 0 to 15
- SCREEN: Base address of the Screen Map in Main Memory, which is equal to 16384
- KBD: Keyboard Register address in Main Memory, which is equal to 24576
For a more in depth explanation of this language, visit https://www.coursera.org/lecture/build-a-computer/unit-6-2-the-hack-assembly-language-AYPo6
- Some way to compile and execute c++ code
- GNU Make (Not required, but makes executing easier)
- Download the source code from github, or clone the repository into Visual Studio
- If you wish to assemble a
.asm
to machine language code:- Add, or create the
.asm
file in the project folder with the assembly code in it. - Go to
main.cpp
and call the functionassemble(file.asm);
- Add, or create the
- If you wish to disassemble machine language code to a
.asm
file:- Add, or create the
.hack
file in the project folder with machine language code (binary) in it. (I decided to use the.hack
file extension to represent machine language code...not to be confused with the hack programming language) - Go to
main.cpp
and call the functiondisassemble(file.hack);
- Add, or create the
- You can dissassemble and assemble at the same time if you wish to do so
- Change directory to
<path/to/projectFolder/src>
- Compile code how you like, or, run the command
make
- After running
make
', execute by running the executeablerun
orrun.exe
- The assembled
.hack
file and/or the disassembled.asm
file will automatically be created in your project folder
Zachary Chi zachchi@tamu.edu
This project is licensed under the MIT License - see the LICENSE.md file for details