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