Return Address

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

Return Address

pawdwanlearner
Well I am not passing the statics test. I have figured out that my return logic is incorrect. Question is it says in the book that the very next instruction after the call is the return address. So are they saying that the return address comes after the all the assembly code that calls the function or are they saying that it should be calculated in the vm implementation somehow.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Return Address

cadet1620
Administrator
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.

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

Re: Return Address

pawdwanlearner
That i understand i suppose my real question is where the rip is derived. Where @rip is the address right after the call.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Return Address

cadet1620
Administrator
In my translator I have a function MakeUniqueLabel(prefix) that returns prefix$n where n is an incrementing static. It's guaranteed to be unique across the entire translation.

WriteCall() gets the unique RIP and writes the push RIP, the rest of the call, and the RIP label.

--Mark
Loading...