Temp Register/Symbol Table?

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

Temp Register/Symbol Table?

jrd
So, in this Chapter 7, the book specifies that base Temp register is allocated to R[5].

However - unlike SP, LCL, ARG, THIS & THAT -  TEMP is not defined as specifically R[5] in the symbol table we constructed back in Chapter 6 for our binary Assembler.

Should we be revising the symbol table as such in the Assembler code, or are their circumstances where TEMP != R[5], in which case we should translate TEMP manually to a reference to R[5] in the VM translator at runtime.

Thoughts pls?

Thanks.

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

Re: Temp Register/Symbol Table?

cadet1620
Administrator
This post was updated on .
jrd wrote
So, in this Chapter 7, the book specifies that base Temp register is allocated to R[5].

However - unlike SP, LCL, ARG, THIS & THAT -  TEMP is not defined as specifically R[5] in the symbol table we constructed back in Chapter 6 for our binary Assembler.

Should we be revising the symbol table as such in the Assembler code, or are their circumstances where TEMP != R[5], in which case we should translate TEMP manually to a reference to R[5] in the VM translator at runtime.
"temp" is a segment, not a register. The VM reference "temp n" refers directly to RAM[5+n]; there is no pointer register involved. "pop temp 3" will generate code like this:
    [code to pop the stack into the D register]
    @8
    M=D
Since the assembler can't parse something like "TEMP+3" there is no reason to add TEMP as a predefined symbol.  (It might be an interesting project to add expressions to @ commands!)

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

Re: Temp Register/Symbol Table?

jrd
Thanks for the response.  So, I think I understand conceptually your response.  However, is there a typo in your reply?

As you stated, if  "'temp n' refers directly to RAM[5+n]", then I could see how "temp 3" could generate a reference to RAM[8] and code like:

[code to Pop top of stack to D-reg]
@8
M = D

However, in your reply, your code indicates a value of @10 (instead of @8).  That confuses me.  How did you arrive at that @10 value?

Can you pls clarify a little further?

Thanks.

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

Re: Temp Register/Symbol Table?

cadet1620
Administrator
jrd wrote
Thanks for the response.  So, I think I understand conceptually your response.  However, is there a typo in your reply?
You are correct. I've fixed my typo.

I must have had my brain set to octal mode 8^)

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

Re: Temp Register/Symbol Table?

moobles
In reply to this post by cadet1620

    [code to pop the stack into the D register]
    @8
    M=D

I assume you mean 'pop the stack into RAM[8] using the D register?
Loading...