Chapter 6: Runtime System

Stack Allocation

. Position of the activation record is not known until run time

. Position is stored in a register at run time, and words in the record are accessed with an offset from the register

. The code for the first procedure initializes the stack by setting up SP to the start of the stack area

MOV #Stackstart, SP

code for the first procedure

HALT

In stack allocation we do not need to know the position of the activation record until run-time. This gives us an advantage over static allocation, as we can have recursion. So this is used in many modern programming languages like C, Ada, etc. The positions of the activations are stored in the stack area, and the position for the most recent activation is pointed to by the stack pointer. Words in a record are accessed with an offset from the register. The code for the first procedure initializes the stack by setting up SP to the stack area by the following command: MOV #Stackstart, SP. Here, #Stackstart is the location in memory where the stack starts.