
CS485G Spring 2015 23
11. Linkage at the calling point for swap(&course1, &course2);
subl $8,%esp # make room for two parameters
movl $course2, 4%esp) # parameter 2
movl $course1, (%esp) # parameter 1
call swap # call
12. When a procedure is called, after the procedure pushes %ebp, the
following values apply.
location meaning
0(%esp) old %ebp
4(%esp) return address
8(%esp) first parameter
12(%esp) second parameter
13. If a local register, such as %ebx, has then been pushed, the %esp
register is not as good a base as the %ebp register for accessing pa-
rameters.
23 Register-saving conventions
1. The compiler writer determines what registers are meant to survive
procedure calls (”non-volatile registers”) and which can be used for
temporary storage by the procedure (”volatile registers”).
2. This convention prevents one procedure call from corrupting an-
other’s data.
3. Say A (the caller) is calling B (the callee).
(a) If A has been using a volatile register, it must save it (on the
stack) before calling B, and pop it when B returns. This situation
is called caller save.
(b) If B needs to use a non-volatile register, it should save it (on the
stack) before doing its work and pop it before returning. This
situation is called callee save.
4. The convention that gcc follows for the x86:
(a) %eax, %ecx, %edx are volatile (caller-save) general-purpose reg-
isters.
Comentarios a estos manuales