Project 8
Project 8
Project 8
In project 7 you built a basic VM translator that implements the VM language’s arithmetic-logical
and push/pop commands. In this project you will extend this translator to handle the VM
language’s branching and function commands. In addition, you will add the capability of translating
multi-file VM programs. This will complete the development of the VM translator that will later
serve as the compiler’s backend.
Objective
Extend the basic VM translator built in project 7 into a full-scale VM translator, designed to handle
multi-file programs written in the VM language. This version of the VM translator assumes that the
source VM code is error-free. Error checking, reporting and handling can be added to later versions
of the VM translator, but are not part of this project.
Contract
Complete the construction of a VM-to-Hack translator, conforming to the VM Specification and
Standard VM Mapping on the Hack Platform. Use your translator to translate the supplied VM test
programs, yielding corresponding programs written in the Hack assembly language. When
executed on the supplied CPU emulator along with supplied test scripts, the assembly programs
generated by your translator should deliver the results mandated by the supplied compare files.
Resources (same as in project 7)
You will need three tools: the programming language in which you implement your VM translator,
and the supplied VM emulator and CPU emulator, available in your nand2tetris/tools folder.
The CPU emulator enables executing and testing the assembly code generated by your VM
translator. If the generated assembly code runs correctly in the CPU emulator, we will assume that
your translator performs as expected. This of course is just a partial test of the translator, but it will
suffice for our purposes.
The VM emulator is a given, visual, VM implementation. It can be used to illustrate, and visualize,
how VM commands and programs impact the stack, the memory segments, and the relevant RAM
areas on the host RAM. Watching how VM commands impact the host RAM will help you figure
out how to realize the same impact using assembly code – a critical requirement for writing the
VM translator.
Since the full-scale VM translator is implemented by extending the basic VM translator built in
project 7, you will also need the source code of the basic VM translator.
Testing
We recommend completing the implementation of the VM translator in two stages. First, extend
the basic VM translator built in project 7 to implement the VM branching commands. Next, extend
the implementation to handle the VM function commands. This staged development allows
unit-testing your implementation incrementally, using the supplied test programs.