|
Different systems will do it different ways, but basically the compiler knows what offset each of the variables is from the stack frame.
In your example:
b is at stack frame - 3 * sizeof int
a is at stack frame - 2 * sizeof int
return address is at stack frame - 1 * sizeof int
d is at stack frame
e is at stack frame + 1 * sizeof int
f is at stack frame + 2 * sizeof int
g is at stack frame + 3 * sizeof int
So the compiler would keep the stack frame address in the frame pointer (probably the previous value would be pushed on the stack before calling the function). Then each access to a local variable becomes and access to a memory location that is the frame pointer + or - and offset.
Note that on many systems the stack grows downward, so the +'s and -'s would be the other way round.
|