Stack Allocation scheme is the simplest Run-Time Storage Management Technique. The storage is allocated sequentially in the stack beginning at one end. Storage should be freed in the reverse order of allocation so that a block of storage being released is always at the top of the stack.
A program consists of data and procedures. On execution of each procedure, some amount of memory is occupied, which has information regarding the procedure, i.e., its actual parameters, number of arguments, return address, return values & local data, etc. That part of memory is the Activation Record of that procedure.
An Activation Record is a data structure that is activated/ created when a procedure/function is invoked, and it contains the following information about the function.
Activation Record in 'C' language consist of
Here, Old SP stores the value of stack pointer of Activation Record of procedure which has called this procedure which leads to the generation of this Activation Record, i.e., It is a pointer to the activation record of the caller.
Two pointers are required for Stack Allocation Scheme −
Actual Parameter− It is used by the calling procedure to supply parameters to the called procedure.
Return value− This field is used by the called procedure to return a value to the calling procedure. The size of each of the above fields is determined at the time when the procedure is called. The size of almost all the fields can be determined at compilation time.
Stack Allocation of Procedure Calls
It can analysis on how the memory is allocated at runtime when a procedure is called & when the value from the procedure is returned.
Consider a procedure P(x1, x2, x3 … … xn).Three address code statement for the call of this procedure will be
call P, n
where 𝐜𝐚𝐥𝐥 𝐏, 𝐧 → calls the procedure P with n number of arguments.
𝐏𝐚𝐫𝐚𝐦 𝐱 → refers to passing actual parameter x.
Execution of all the following statements related to the procedure will perform stack allocation at runtime.