外文原文
From:《J2EE in the Real World》
Author:Jack Joney
Computer Systems A programmer's Perspective
深入理解计算机系统
原文:
Stack Frame for
calling procedure
+8 +8
+4 +4
%ebp 0 %ebp 0
Stack Frame for
fib_rec
-20 -20
%esp -24 -24
%esp -40
After set up Before first recursive call
Figure 3.21: Stack Frame for Recursive Fibonacci Function. State of frame is shown after initial set up (left), and just before the first recursive call (right).
For the nonterminal condition, instructions 10 to 12 set up the first recursive call. This involves allocating12 bytes on the stack that are never used, and then pushing the computed value n-2. At this point, the stack frame will have the form shown on the right side of Figure 3.21. It then makes the recursive call, which will trigger a number of calls that allocate stack frames, perform operations on local storage, and so on. As each call returns, it deallocates any stack space and restores any modified callee save registers. Thus, when we return to the current call at line 14 we can assume that register %eax contains the value returned by the recursive call, and that register %ebx contains the value of function parameter n. The returned value (local variable prev_val in the C code) is stored in register %esi (line 14). By using a callee save register, we can be sure that this value will still be available after the second recursive call.
Instructions 15 to 17 set up the second recursive call. Again it allocates