What is Static Allocation?

Compiler DesignProgramming LanguagesComputer Programming

It is the simplest allocation scheme in which allocation of data objects is done at compile time because the size of every data item can be determined by the compiler. The main function of static allocation is to bind data items to a particular memory location. The static memory allocation procedure consists of determining the size of the instruction and data space.

Recursive Subprogram and Arrays of adjustable length are not permitted in a language. In static allocation, the compiler can decide the amount of storage needed by each data object. Thus, it becomes easy for a compiler to find the address of these data in the activation record. FORTRAN uses this kind of storage allocation strategy.

The binding of the name with the amount of storage allocated does not change at runtime. Therefore, the name of this allocation is static allocation. In static allocation, the compiler can decide the amount of storage needed by each data object. Therefore, it becomes easy for a compiler to find the address of these data in the activation record.

At compile time compiler can fill the addresses at which the target code can find the data it operates on.

Implementation of the 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− An address of the activation record.

callee.code_area− An 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 an action statement.

Implementation of halt statement

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

Advantages

  • It is easy to implement.
  • It allows type checking during compilation.
  • It eliminates the feasibility of running out of memory.

Disadvantages

  • It is incompatible with recursive subprograms.
  • It is not possible to use variables whose size has to be determined at run time.
  • The static allocation can be done if the size of the data object is known as compile time.
  • The data structure cannot be created dynamically, in the sense that, the static allocation cannot manage the allocation of memory at runtime.


raja
Updated on 08-Nov-2021 10:58:18

Advertisements