Stack Allocation of Space

Almost all compilers for languages that use procedure, functions, or methods manage their run-time memory as a stack. Whenever a procedure is called, the local variable’s space is pushed into a stack and popped off from the stack when the procedure terminates.

Activation Trees

A program is a set of instruction with some operation associated with it. The sequence in which the procedure executes is known as activation. We also assume that a procedure executes in a sequential manner, and this sequence is easily represented by a tree known as the activation tree.

The following example illustrates the nesting of procedure calls:

Example

The above code shows that array ‘a’ reads nine integers and sorts them using the recursive quicksort algorithm.

The task of the main function is to invoke the function readArray, sets the sentinels, and then call the function quicksort on the entire data array.

The code below shows a set of calls that might result from the execution of a program.

The figure below shows the possible activation tree for the given code.

Stack Allocation of Space

Activation Records

A run-time stack known as a control stack manages the procedure calls and returns. The control stack stores the activation record of each live activation. The top of the stack will hold the latest activation record.

The content of the activation record is given below. This record may vary according to the implemented languages.

    Actual parameters
      Returned values
        Control link
        Access link
   Saved machine status
        Local data
        Temporaries

Temporaries: The values which arise from the evaluation of expression will be held by temporaries.

Local data: The data belonging to the execution of the procedure is stored in local data.

Saved machine status: The status of the machine that might contain register, program counter before the call to the procedure is stored in saved machine status.

Access link: The data’s information outside the local scope is stored in the access link.

 Control link: The activation record of the caller is pointed by the control link.

Returned values: It represents the space for the return value of the called function if any.

Actual parameter: It represents the actual parameters used by the calling procedure.

Pin It on Pinterest

Share This