Unformatted text preview: umbers along the left of the frames indicate the address offsets relative to the frame pointer. The stack frame for caller includes storage for local variables arg1 and arg2, at positions and relative to the frame pointer. These variables must be stored on the stack, since we must generate addresses for them. The following assembly code from the compiled version of caller shows how it calls swap_add.
Calling code in caller
1 2 3 4 5 leal -4(%ebp),%eax pushl %eax leal -8(%ebp),%eax pushl %eax call swap_add Compute &arg2 Push &arg2 Compute &arg1 Push &arg1 Call the swap_add function Observe that this code computes the addresses of local variables arg2 and arg1 (using the leal instruction) and pushes them on the stack. It then calls swap_add. The compiled code for swap_add has three parts: the “setup,” where the stack frame is initialized; the “body,” where the actual computation of the procedure is performed; and the “ﬁnish,” where the stack state 138 CHAPTER 3. MACHINE-LEVEL REPRESENTATION OF C PROGRAMS
Stack Frame for caller %ebp 0 -4 -8 - 12 %esp - 16 Stack Frame for...
View Full Document