For a question paper i'm doing I got a question on stack frames:
Consider the following function in Nada (a made up language), the language used in the lectures:
function f(x,y)
begin
var z
z := y - x;
return z * z;
end;
Such a function might be called like this:
n := f(a+2,b*3)
Using diagrams to illustrate your answer, explain the sequence of events when the function call above is executed, showing how the stack frame is built on entry to the function and destroyed on exit from it, and how the base pointer register is used when accessing the parameters x and y and the local variable z.
I've answered this question and this is the stack frame I produced:
I just want someone to correct this for me if parts of it are wrong...or produce a new stack frame (if anyone's got the time). I'll really appreciate the help.
It depends on the calling conventions.
But if you assume that it is using _cdecl calling convention, since you mention a base pointer:
http://i.stack.imgur.com/5vQVB.jpg
Other calling conventions can use registers, etc. Optimizations can further change this, as the compiler will inline code, do call kinds of things with to rearrange the code for CPU pipelining, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With