Aptr is in edx bptr in ecx result in esi cnt in ebx

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: ge when the procedure is called and deallocating it when it returns. Figure 3.19 shows the C code for a recursive Fibonacci function. (Note that this code is very inefficient—we intend it to be an illustrative example, not a clever algorithm). The complete assembly code is shown as well in Figure 3.20. Although there is a lot of code, it is worth studying closely. The set-up code (lines 2 to 6) creates a stack frame containing the old version of %ebp, 16 unused bytes,2 and saved values for the callee save registers %esi and %ebx, as diagrammed on the left side of Figure 3.21. It then uses register %ebx to hold the procedure parameter n (line 7). In the event of a terminal condition, the code jumps to line 22, where the return value is set to 1. 2 It is unclear why the C compiler allocates so much unused storage on the stack for this function. 3.7. PROCEDURES 141 1 2 3 4 5 6 fib_rec: Setup code pushl %ebp movl %esp,%ebp subl $16,%esp pushl %esi pushl %ebx Body code Save old %ebp Set %ebp as frame Allocate 16...
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