Accessing Instruction Pointer

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Accessing Instruction Pointer

twitu
I have realised that writing  separate jump statements to store the results of each boolean operation is infeasible because:
1. Creating new Label names dynamically from vm to asm is infeasible
2. Very long output asm file

The only solution is to make a universal/general boolean assignment of true or false using a subroutine as i found here http://nand2tetris-questions-and-answers-forum.32033.n3.nabble.com/translating-eq-to-asm-tp4028370p4028371.html

However to use this without additional labels i will need access to instruction pointer, which i could not find in the given documentation and chapter 7 pdf. Do you have a solution to this problem ?
Reply | Threaded
Open this post in threaded view
|

Re: Accessing Instruction Pointer

cadet1620
Administrator
There is no way to store the PC value. You must use jump instructions and labels in the generated ASM code.

Take a look at projects/06/pong/Pong.asm. That is the output from a VM Translator. There are about 900 code labels.

You do not need to write assembly language routines for the compare commands (or 'call' and 'return' commands in project 8). Most students do not. There are only 9 compare commands in the test code so the savings from the ASM routines is minimal.

The labels are not dynamic. They do not change during execution of the ASM program. They must be unique for each VM statement that is translated, but that is under complete control of the translator when it writes the ASM code.

That is easy to do by adding a serial number to every label name that the VM Translator generates. The first 'eq' command uses labels like 'EQ_TRUE$1'. The next 'eq' would use 'EQ_TRUE$2' in its code.

--Mark
Reply | Threaded
Open this post in threaded view
|

Re: Accessing Instruction Pointer

twitu
Thanks for the help. Finished VM Part 1. I implemented subroutines for eq, gt, and lt.