StackTest commands eq, gt, lt

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

StackTest commands eq, gt, lt

gs99
Page 141 says "Each VM command is translated by the VM translator into Hack assembly code."

No examples are provided, so I have some basic questions.

In SimpleAdd, the push and add VM commands each generate multiple assembly code lines, correct?

Stack processing requires manipulation of objects by the VM translator code; it is not represented in assembly code. Examples: updating the stack pointer value, determining which values on the stack are to be included in add command.  

In StackTest, do the VM commands that return boolean values generate any assembly code?
I don't recall assembly code that "just compares"; it was included in a jump.

So my question is: Do certain VM commands not translate into Hack assembly code?









Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: StackTest commands eq, gt, lt

cadet1620
Administrator
gs99 wrote
In SimpleAdd, the push and add VM commands each generate multiple assembly code lines, correct?
Correct. All VM commands generate at least one line of assembly code. Some like call and return generate dozens of lines of code.
Stack processing requires manipulation of objects by the VM translator code; it is not represented in assembly code. Examples: updating the stack pointer value, determining which values on the stack are to be included in add command.  
The stack pointer is the built-in RAM variable SP. The simplest code to increment the stack pointer would be
    @SP
    M=M+1
The add command generates asm code that does
    RAM[SP-2] = RAM[SP-2]+RAM[SP-1]
    SP = SP-1
In StackTest, do the VM commands that return boolean values generate any assembly code?
I don't recall assembly code that "just compares"; it was included in a jump.
eq generates code that does
    if (RAM[SP-1] = RAM[SP-2])
    then
        RAM[SP-2] = -1
    else
        RAM[SP-2] = 0
    SP = SP-1

I'll email you a sample VM translation that I don't want to post on the forum.

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: StackTest commands eq, gt, lt

gs99
StackTest.cmp provides correct values for RAM after doing eq(256), lt(257), and gt(258).

How can I know correct values for the other commands (add, sub, neg, and, or)?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: StackTest commands eq, gt, lt

cadet1620
Administrator
gs99 wrote
StackTest.cmp provides correct values for RAM after doing eq(256), lt(257), and gt(258).

How can I know correct values for the other commands (add, sub, neg, and, or)?
The result of the complete expression evaluation using all 5 operators is in RAM[259]. If you need the values after each individual arithmetic command you will need to calculate that yourself or single step using the VM emulator.

--Mark
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: StackTest commands eq, gt, lt

gs99
Thanks, I forgot about using VM Emulator. This helped me resolve some problems; StackTest is done!

When stepping thru in CPU Emulator, it’s difficult keeping track of where I am. All the code looks the same.

So I added some code to VM translator to generate another file I call StackTest.va (VM/asm).
While the program is generating asm lines, it also writes the va file that includes VM and asm code in this format:
Initialize SP
0    @xxx
1    D=A
2    @xxx
3    M=D
                SP: xxx
Push constant 17
4    @17
5    D=A
      (EXnnn)
6    D=-1

After running the VMt program, I print the va file.
Seeing the VM commands and associated asm code/lines helps me navigate.
The calculated SP value is shown at the end of each VM/asm group.
   
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: StackTest commands eq, gt, lt

sankar.lp.gym
This post was updated on .
In reply to this post by gs99
Where can i get more information on Hack Assembly code


[advertising link deleted. --admin]
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: StackTest commands eq, gt, lt

cadet1620
Administrator
sankar.lp.gym wrote
Where can i get more information on Hack Assembly code
Book chapters 4 and 6, and the lecture slides for them are available on the N2T Study Plan page.

The slides are the PowerPoint icon links in the Lecture column.

--Mark
Loading...