Nested Call Error; A=-1 illegal memory address

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

Nested Call Error; A=-1 illegal memory address

JM
So far my VM translator has passedthe two program flow tests, as well as the SimpleFunction test. However, when I run the NestedCall test I get a CPU error because -1 ends up in the LCL register.

I walked through the code and it looks like all the returns, functions call etc. are working...until the return for Sys.main. At that point, it looks like the program is setting the LCL, ARG, THIS, and THAT pointers to M[260]-M[257]. This makes me think that somewhere in the program these pointers are improperly set. However, I can't see any issue with my VM code for the return and function commands, and they worked properly in SimpleFunction test. The call command also appears to work properly.

Would someone be willing to take a look at the assembly code my translator generates and help me identify what the issue is? Here's a link to my code: https://drive.google.com/open?id=1LasX9WVKtxkJmtXJLlN1CvRgmxcieGXH 

I would really appreciate any insight! However, if you do see what the problem is, I'd appreciate it if you only gave a hint for how to fix it.
JM
Reply | Threaded
Open this post in threaded view
|

Re: Nested Call Error; A=-1 illegal memory address

JM
I think I may have fixed this problem...now I just have a comparison failure. Hopefully will be able to fix this one!
Reply | Threaded
Open this post in threaded view
|

Re: Nested Call Error; A=-1 illegal memory address

Lozminda
In reply to this post by JM
I seem to remember that it comes up a bit on this forum, when calling  to a function with no arguments there can be an overlap of the return value (address) and LCL i think.

 Sep 11, 2016; 11:15pm cadet1620 cadet1620
The return address label goes after the jump to the called function, before the code for the next VM statement.

// call Sys.error 1
    @RIP$123
    D=A
code to push D on the stack
code to build the stack frame
    @Sys.error
    0;JMP
(RIP$123)
// pop temp 0
    @SP

One of the tricky things to watch out for is that when a function with no parameters returns, argument 0 and the RIP are at the same location on the stack. Don't clobber the RIP when you preposition the return value.


Could it be the above problem? There are quite a few threads on Nabble that i found really interesting. Sorry I'm unable to log on to your google drive..