Run-Time Storage Management

Run-Time Storage Management

Every executing program has its own logical address space. Logical address space is partitioned into:

  1. Code: It is responsible for storing the executable target code.
  • Static: It is used to holdglobal constant and compiler generate data.
  • Heap: It is a dynamically managed area used to hold data objects.
  • Stack: It is thedynamically managed area used to hold activation records.

The address in the target code can be described in two ways:

  1. Static Allocation
  1. Stack Allocation

Static Allocation

In static allocation, the size and layout of the activation records are decided by the information stored in the symbol table. The activation record’s first location is used to store the return address. The three address code associated with code generation for simplified procedure call and return are the following:

  • Call
  • Return
  • Halt
  • Action, a placeholder for the other statements.

The code that needs to implement static allocation is the following:

The following set of target-machine instructions can implement call callee statement:

ST                  callee.staticArea,            #here + 20       

BR                 callee.codeArea

callee.staticArea: It is a constant that represents the address of the starting point of the activation record for the callee.

callee.codeArea: It is a constant that represents the address of the first instruction for the called procedure.

# here + 20: It is a literalthatrepresents theaddress of the instruction.

A return statement can be implemented by the following code:

BR                 *callee.staticArea

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

HALT: It is the final instruction. This instruction returns control to the operating system.

ACTION: It is the set of machine instructions used to execute an action statement.

Stack Allocation

A static allocation can be converted into a stack allocation using relative addresses for storage in activation records. The position of the activation record for a procedure is not known in stack allocation until run-time. The activation record's position is usually stored in a register, so words in the activation record can be accessed as offsets from the value.

The code to initialize the stack is as follows:

LD     SP,     # stackStart              // initialize the stack

HALT                                          // terminate execution

The code to implement a call statement in stack allocation is the following:

   ADD SP, SP,   #caller.recordSize       // increment stack pointer

   ST 0(SP), #here + 16                       // Save return address

   BR calee.codeArea                      // jump to the callee

#caller.recordSize: It represents the size of activation records.

 #here + 16:  It is the address of the instruction following BR.

The return statement consist of two parts:

 BR      *0(SP)                 // return to caller

SUB SP, SP, # caller.recordSize       // Decrement stack pointer


Related Topics

Errors in Compiler Design

Introduction Errors in compiler design refer to mistakes or issues that arise during the process of execution of the program. A compiler is a program that translates source code written in...

4 minutes read.

Switch Case Statement Compiler Design

Case Statement The “case” or “switch” statement is available in various languages. The following is the syntax for the case statement: switch (E)  {             case V1: S1             case V2: S2 ...

1 minute read.

Shift Reduce Parsing in Compiler Design

Like the bottom-up parsing, the shift reduce parser also builds the parse tree from the leaves (bottom) to the root (up). The LR parser is a more versatile variation of...

4 minutes read.

Basic Blocks and Flow Graphs in Compiler Design

Basic Blocks and Flow Graphs In this section, we are going to learn how to work with basic block and flow graphs in compiler design. Basic Block The basic block is a set...

3 minutes read.

Run-Time Storage Management

Run-Time Storage Management Every executing program has its own logical address space. Logical address space is partitioned into: Code: It is responsible for storing the executable target code. Static: It is used to...

3 minutes read.

SLR 1 Parsing Compiler Design

SLR(1) Parsing It is a simple LR parsing. Most of the function of this parsing is the same as LR(0) parsing. The parsing table for both the parser vary. The SLR(1)...

5 minutes read.

Syntax Analysis Compiler Design

Syntax Analysis This article will describe the parsing method used in the compiler. The grammatical rule of programming language can be constructed with the help of context-free grammars or BNF (Backus–Naur...

3 minutes read.

Symbol Table Compiler Design

Symbol Table It is an important data structure used by the compiler. It stores information about various entities such as object, class, variable names, functions name, interfaces, procedure, literals, string etc.  The...

3 minutes read.

Compiler Design Tutorial

Our compiler design tutorial will provide all the information about compiler from basic to advanced level. This compiler tutorial will help the student for their semester as well as for...

3 minutes read.

Finite State Machine

Finite State Machine A finite state machine is a simple machine to recognize patterns. It takes a string of symbols as the input and changes its state to another state, but...

3 minutes read.

Bottom-Up Parsing in Compiler Design

Bottom-Up Parsing A bottom-up parsing constructs the parse tree for an input string beginning from the bottom (the leaves) and moves to work towards the top (the root). Bottom-up parsing is...

6 minutes read.

Data Flow Analysis in Compiler Design

Data Flow Analysis All the optimization techniques we have learned earlier depend on data flow analysis. DFA is a technique used to know about how the data is flowing in any...

3 minutes read.

Intermediate-Code Generator Compiler Design

Intermediate-Code Generator The process of translating a source language into machine code for a given target machine is done by intermediate-code. It lies between the high-level language and the machine language....

2 minutes read.

Code Generation

Code Generation The last phase of the compiler is code generation. It is the compiler's back-end that makes multiple passes over the IR before generating the target program. The code generator's...

4 minutes read.

Syntax-Directed Translation

Syntax-Directed Translation A context-free-grammar with some additional rules is known as a syntax-directed definition. In SDT, attributes are associated with grammar symbols and rules are associated with productions. The attributes can...

3 minutes read.

Stack Allocation of Space

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...

2 minutes read.

Parsing in Compiler Design

Parsing is the term used to describe the process of converting data between different formats. The parser can carry out this operation. The parser is a part of the translator...

4 minutes read.

Evolution of Programming Languages in Compiler Design

The Evolution of Programming Languages The first computer came in the 1940s and was programmed in a binary language that told the computer what operations are to be performed and in...

4 minutes read.

Three-Address Code

Three-Address Code If there is at most one operator on the right side of the instruction, then the instruction will be the three-address code so that no arithmetic expressions are permitted....

2 minutes read.

Run-Time Environments

Run-Time Environments Storage Organization Every target program has its own logical address, and an executable program runs in it. The logical address space has the location for each program value. The...

2 minutes read.