L12 leal eaxeax4edx movl ecxeax leal eaxedx2eax

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: caller • • • +12 +8 +4 %ebp %esp 0 -4 yp (= &arg2) xp (= &arg1) Return Address Saved %ebp Saved %ebx Stack Frame for swap_add Saved %ebp arg2 arg1 &arg2 &arg1 Figure 3.18: Stack Frames for caller and swap add. Procedure swap add retrieves its arguments from the stack frame for caller. is restored and the procedure returns. The following is the setup code for swap_add. Recall that the call instruction will already push the return address on the stack. Setup code in swap_add 1 2 3 4 swap_add: pushl %ebp movl %esp,%ebp pushl %ebx Save old %ebp Set %ebp as frame pointer Save %ebx Procedure swap_add requires register %ebx for temporary storage. Since this is a callee save register, it pushes the old value on the stack as part of the stack frame setup. The following is the body code for swap_add: Body code in swap_add 1 2 3 4 5 6 7 movl movl movl movl movl movl addl 8(%ebp),%edx 12(%ebp),%ecx (%edx),%ebx (%ecx),%eax %eax,(%edx) %ebx,(%ecx) %ebx,%eax Get xp Get yp Get x Get y Store y at *xp Store x at *yp Set return value = x+y This code retrieves its arguments from the stack frame for caller. Since the frame pointer...
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