Compiler Design and Construction - Old Questions

9.  What is activation record? Discuss the different activities performed by caller and callee during procedure call and return.

6 marks | Asked in 2075

A program is a sequence of instructions combined into a number of procedures. Instructions in a procedure are executed sequentially. A procedure has a start and an end delimiter and everything inside it is called the body of the procedure. The procedure identifier and the sequence of finite instructions inside it make up the body of the procedure.

The execution of a procedure is called its activation. An activation record contains all the necessary information required to call a procedure. An activation record may contain the following units (depending upon the source language used).

Activation Record

In any function call, the routine that initiates the call is called caller and the routine that is being called is known as callee

Activities performed by caller and callee during procedure call and return are given below:

On the caller's side:

  • save registers for later use
    • stack push
    • caller-save registers
  • arrange for the procedure arguments to be found by the procedure
    • copy some arguments to registers
    • push additional arguments onto stack
  • call the procedure
    • save return address in register or on stack
    • jump to procedure starting address
  • later, the return value (if any) is in a pre-determined place, and control is transfered back to the return address
  • copy the return value
    • move to another register or store to memory (pop the stack if necessary)
  • throw away the procedure arguments
    • adjust stack pointer
  • restore saved registers
    • stack pop
  • continue

On the callee's side:

  • control is transfered from the caller to the starting address
    • return address is in register or on stack
    • arguments are in registers and on stack
  • save registers for later use
    • stack push
    • arguments and return address
    • caller's frame pointer
    • other callee-save registers
  • allocate storage for automatic local variables
    • set the frame pointer, adjust the stack pointer
    • assign initial values
  • allocate storage for temporaries
    • adjust the stack pointer
  • work
    • stack may be used for additional temporaries
    • push, use, pop
  • put return value in appropriate place
    • register or stack
  • throw away the local variables and temporaries
    • adjust the stack pointer
  • restore saved registers
    • stack pop
    • arguments and return address
    • caller's frame pointer
    • other callee-saved registers
  • jump through the return address register