This program compiles Hack virtual machine code files into Hack assembly code.
The hack virtual machine specifications are linked below:
Part 1
Part 2
make
vm_translator.exe input_path
input_path - Path to .vm file or directory containing .vm files
The program generates an output file with a .asm
extension and a basename equal to the input path's.
The program consists of two classes used by main:
Parser
- Reads through each instruction in the input file, parsing it into fields
Translator
- Generates sequences of assembly commands for each virtual machine command
The main function starts by iterating through all the Parser
's instructions, only looking for label declarations, and adds them to the SymbolTable
with their corresponding address.
The parser is then reset and another pass is made. This time, everything else is parsed. Labels are converted to their respective addresses in the SymbolTable
before the entire instruction is then converted to a 16-bit binary Hack machine instruction and output.