Home | | Compiler Design | Run-Time Storage Management

Chapter: Principles of Compiler Design : Code Generation

Run-Time Storage Management

Information needed during an execution of a procedure is kept in a block of storage called an activation record, which includes storage for names local to the procedure.

RUN-TIME STORAGE MANAGEMENT


• Information needed during an execution of a procedure is kept in a block of storage called an activation record, which includes storage for names local to the procedure. The two standard storage allocation strategies are:

1. Static allocation 2. Stack allocation

 

   In static allocation, the position of an activation record in memory is fixed at compile time.

   In stack allocation, a new activation record is pushed onto the stack for each execution of a

 

procedure. The record is popped when the activation ends.

 

     The following three-address statements are associated with the run-time allocation and deallocation of activation records:

1.  Call,

2.  Return,

3.   Halt, and

4.   Action, a placeholder for other statements.

 

   We assume that the run-time memory is divided into areas for:

 

1.  Code

2.  Static data

3.  Stack

 

Static allocation

Implementation of call statement:

The codes needed to implement static allocation are as follows:

MOV #here + 20, callee.static_area /*It saves return address*/

 

GOTO callee.code_area /*It transfers control to the target code for the called

procedure */

where,

callee.static_area - Address of the activation record

callee.code_area - Address of the first instruction for called procedure

 

#here + 20 - Literal return address which is the address of the instruction following GOTO.

 

Implementation of return statement:

A return from procedure callee is implemented by : GOTO *callee.static_area

This transfers control to the address saved at the beginning of the activation record.

 

Implementation of action statement:

The instruction ACTION is used to implement action statement.

 

Implementation of halt statement:

The statement HALT is the final instruction that returns control to the operating system.

 

Stack allocation

 

Static allocation can become stack allocation by using relative addresses for storage in activation records. In stack allocation, the position of activation record is stored in register so words in activation records can be accessed as offsets from the value in this register.

 

The codes needed to implement stack allocation are as follows:

 

Initialization of stack:

MOV #stackstart , SP /* initializes stack */

Code for the first procedure

HALT /* terminate execution */

 





Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Principles of Compiler Design : Code Generation : Run-Time Storage Management |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.