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-M. 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.
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
code to push D on the stack
code to build the stack frame
// pop temp 0
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..