CSC448: Code Generation: Run-Time Environment V [58/133] |
What if recursive procedure calls are permitted?
A stack allows fast allocation and deallocation of activation records.
The position of local variables is not known at compile-time.
Generated code expects to find local variables at a fixed offset from the current activation record (in a C-like language).
On x86:
ebp
(Stack-Frame Base Pointer) register
points to the current activation record.
-4(%ebp)
refers to the memory
location that is 4 bytes (or one word = one 32 bit
integer) below the area pointed to by the base pointer.
The following code moves the integer constant 3 into that
location:
movl $3, -4(%ebp)
esp
(Stack Pointer) register points to
the top element of the stack.