Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this stack frame I produced right?

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:

sackframe 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.

like image 285
Mr Teeth Avatar asked Jun 08 '11 01:06

Mr Teeth


1 Answers

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.

like image 86
klhurley Avatar answered Nov 07 '22 05:11

klhurley