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

Target Machine

Target Machine A target machine is a byte-addressable machine. This machine has n general-purpose registers, R0, R1,.....Rn-1. A Simple Target Machine Model has three-address instruction. A full-edged assembly language would have...

3 minutes read.

Lexical Analysis in Compiler Design

Lexical Analysis It is the first phase of the compiler. As we know, it is also known as a scanner. The input for lexical analysis is source code. After taking source...

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

Storage Allocation

Storage Allocation The storage allocation represents memory management. The allocation of memory can be done in the following ways: Static AllocationStack AllocationHeap Management Static Allocation: It is a procedure used for the allocation of...

1 minute read.

S-attributed and L-attributed SDTs

S-attributed and L-attributed SDTs STD stands for Syntax Directed Translation. When we associate some informal notations called semantic rules and the grammar, they are known as STD. So we can say...

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

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.

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.

Boolean Expression in Compiler Design

Boolean Expression The translation of conditional statements such as if-else statements and while-do statements is associated with Boolean expression's translation. The main use of the Boolean expression is the following: Boolean expressions...

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

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.

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.

Machine-Independent Optimizations in Compiler Design

Machine-Independent Optimizations The main aim of machine-independent optimization is to improve the generated intermediate code so that compiler can get better target code. Eliminating unwanted code from the object code or replacing...

8 minutes read.

Derivation and Parse Tree in Compiler Design

Derivation and Parse Tree In this article, we will learn Derivation and Parse Tree. Derivations The parse tree can be constructed by taking a derivational view in which production is treated as rewriting...

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

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.

Regular Expression | Compiler Design

Regular Expression A regular expression is a set of patterns that can match a character or string. It can also match alternative characters or strings. The grammar defined by the regular...

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

LALR 1 Parsing | Compiler Design

LALR (1) Parsing The LALR parsing refers to the "lookahead LR" that has many lesser steps than typical parsers based on LR(1) items. For constructing the LALR(1) parsing table, the canonical...

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