CSE365
Elements of Computing Systems
|
Assignment 6
Due Date: 2015-3-1, 11:59pm
Objective
Write a VM-to-Assembler translator that produces behavior that passes the tests. You should work incrementally, starting with the first test and then moving on the next once that works, in the following order:
- SimpleAdd.vm
- StackTest.v
- BasicTest.vm
- PointerTest.vm
- StaticTest.vm
Software
This assignment requires you to write code.
Stubs for Java and Python are provided in your repos.
Your code will be run with one of the following commands:
- Java - java VMTranslator Something.vm
- Python - python vm_translator.py Something.vm
- C/C++ - ./vm_translator Something.vm
Tips and Resources
- As noted in the last assignment, there are no more free chapters of the book available.
- You will be much happier if you write comments into your assembly code, as noted in the lecture.
- It may be helpful to write your own helper methods such as
- A method to write a number of commands to the output at once.
- A method for pushing the contents of register D onto the stack.
- A method for popping a number off the stack into register D.
- Writing the comparison operators requires that you create unique labels in your assembly code. They can be simple like (_label1) as long as you keep incrementing the number.
- For static variables, you must use named variables instead of just their location. Hence, each static memory address should be translated to a variable name of the form Filename.number such as StaticsTest.1. The filename is provided to you with the set_filename method.
- The provided code can take either a vm file or a directory as input. If its a file Foo.vm, then it will be translated to Foo.asm in the same folder. If its a directory, for each subdirectory, the translator will compile all of the vm files in the directory into one asm file in that folder, with the same name as the folder. This functionality is not needed in this assignment, but will be useful next week. Also, its a nice way to translate all of the vm files provided at once.
- Once again, you do not have to check for errors, including whether a given segment index is valid.
- When running the add operation, conceptually you need to pop two numbers off of the stack and push the result of the addition back onto the stack. However, you can really just pop one number off, store it in D and then calculate the sum in place.
- For the test operations (eq, gt, lt), you need to perform a subtraction, and then write either -1 or 0 based on the result. The easiest way to do this is with a jump based on the result of the subtraction.
- In our computer, we were primarily accessing memory with an absolute address. In the vm, its either a) the top thing on our stack or b) accessed with a starting point and an offset.
- The segments argument, local, this and that all have dynamic starting points, so you need to load the respective pointer (ARG, LCL, THIS or THAT), add the index to it and then operate on that memory location.
- For pointer and temp, the starting points are always the same location...3 and 5 respectively, i.e. pointer 1 always points to MEM[4] and temp 2 always points to MEM[7].
- The static segment is also always stored in the same location. But since multiple vm files can be loaded into the same assembly file, if we just used the same starting point / offset combo, the different files could voerwrite the memory. So instead, we let the assembler take care of allocating space, by giving each file's static variables a unique name. If the file name is Washington.vm, we should translate static 2 to an address of @Washington.2.
|