Aside why avoid integer multiply in older models of

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

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 “finish,” 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

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online