Why do we need to CALL the sys.init function?

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

Why do we need to CALL the sys.init function?

thedumbone
When I'm using the following commands:

@Sys.init
0;JMP

to directly jump to the Sys.init function, I'm not getting the correct values in RAM. But when I use a helper function write_call (to generate assembly for "call Sys.init 0") I'm passing the tests. My question is, why do we need to push return address, THIS, THAT, LCL etc. to the stack? Initially, I think that those addresses should contain garbage values anyway. Also, once the sys.init function is called, isn't it supposed to be in an infinite loop? So why do we need to push those values if we are never using it?

Edit: i'm using both (direct jump and calling sys.init) after setting sp = 256
Reply | Threaded
Open this post in threaded view
|

Re: Why do we need to CALL the sys.init function?

ivant
IIRC you don't really need to call Sys.init as: 1. it doesn't take any parameters and 2. it does not return. However the tests were written assuming that you still call it instead of just jumping to it, so they will fail.

My guess is that the authors chose this in order to make the whole process more consistent. Sys.init is called only once so there's not much to gain from optimizing this call anyway.
Reply | Threaded
Open this post in threaded view
|

Re: Why do we need to CALL the sys.init function?

pm100
The call will also set up stack space for any local variables used by Sys.init. But, for sure, the .cmp files are set to expect to see a Sysy.init frame on the stack when the test ends by calling Sys.halt