0
39kviews
What is an activation record? Draw diagram of General Activation record and explain the purpose of different fields of an activation record.

Subject: system programming and compiler construction

Topic: Intermediate Code Generation

Difficulty: Medium

1 Answer
2
625views
  • A program as a source code is merely a collection of text (code, statements etc.) and to make it alive, it requires actions to be performed on the target machine.
  • A program needs memory resources to execute instructions.
  • A program contains names for procedures, identifiers etc., that require mapping with the actual memory location at runtime.
  • By runtime, we mean a program in execution.
  • Runtime environment is a state of the target machine, which may include software libraries, environment variables, etc., to provide services to the processes running in the system.
  • Runtime support system is a package, mostly generated with the executable program itself and facilitates the process communication between the process and the runtime environment.
  • It takes care of memory allocation and de-allocation while the program is being executed.

Activation Records

enter image description here

  • Recall that an activation is an execution of a subprogram. In most languages, local variables are allocated when this execution begins (activation time).
  • The storage (for formals, local variables, function results etc.) needed for an activation is organized as an activation record (or frame).
  • In a language with recursion, each simultaneous activation of a recursive subprogram can have different parameters, different values for local variables, return a different result.

    • Each activation needs its own activation record
    • The number of activation records needed isn’t known at compile time
    • Allocation of activation records is dynamic, and local variables are stack dynamic (unless declared static).
  • 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).
Return value
Parameters
Local Data
Temporary Data
Links(optional)
Status

Activate Record

  • It is used to store the current record and the record is been stored in the stack.
  • It contains return value .After the execution the value is been return.
  • It can be called as return value. Parameter
  • It specifies the number of parameters used in functions.

Local Data

  • The data that is been used inside the function is called as local address Temporary Data
  • It is used to store the data in temporary variables.

Links

  • It specifies the additional links that are required by the program.

Status

  • It specifies the status of program that is the flag used.
Temporaries Stores temporary and intermediate values of an expression.
Local Data Stores local data of the called procedure.
Machine Status Stores machine status such as Registers, Program Counter etc., before the procedure is called.
Control Link Stores the address of activation record of the caller procedure.
Access Link Stores the information of data which is outside the local scope.
Actual Parameters Stores actual parameters, i.e., parameters which are used to send input to the called procedure.
Return Value Stores return values.
  • Whenever a procedure is executed, its activation record is stored on the stack, also known as control stack.
  • When a procedure calls another procedure, the execution of the caller is suspended until the called procedure finishes execution.
  • At this time, the activation record of the called procedure is stored on the stack.
  • We assume that the program control flows in a sequential manner and when a procedure is called, its control is transferred to the called procedure.
  • When a called procedure is executed, it returns the control back to the caller. This type of control flow makes it easier to represent a series of activations in the form of a tree, known as the activation tree.

To understand this concept, we take a piece of code as an example:

            . . .
            Printf (“Enter Your Name: “);
            Scanf (“%s”, username);
            Show_data (username);
            printf (“Press any key to continue…”);
            . . .
             int show_data (char *user)
            {
            Printf (“Your name is %s”, username);
             return 0;
             }
             . . .
  • Below is the activation tree of the code given.

enter image description here

  • Now we understand that procedures are executed in depth-first manner, thus stack allocation is the best suitable form of storage for procedure activations.
Please log in to add an answer.