Table of contents
1.
Introduction
2.
Static Allocation
2.1.
1. Implementing Call Statement
2.2.
2. Implementing Return Statement
2.3.
3. Implementing Action Statement
2.4.
4. Implementing Halt Statement
3.
Stack Allocation
3.1.
1. Initializing Stack Statement
3.2.
2. Implementing Call Statement
3.3.
3. Implementing Return Statement
4.
Frequently Asked Questions
4.1.
What is an Activation Record?
4.2.
Name the different ways in which the address of the target code can be described.
4.3.
Name the different address statements associated with allocation and de-allocation of activation records.
4.4.
Name the different steps involved in implementing the static allocation.
4.5.
Name the different steps involved in implementing the stack allocation.
5.
Conclusion
Last Updated: Mar 27, 2024
Easy

Run Time Environments

Author Prachi Singh
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?
Compiler Design

Introduction

The data required during the program's execution is stored in an activation record block. 

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

1. Static Allocation

2. Stack Allocation

Activation Record has a fixed position reserved during compile time in Static Allocation. A new activation record is pushed into the stack for each execution in Stack Allocation.

The different address statements associated with allocation and de-allocation of activation records are

  1. Call
  2. Return
  3. Halt 
  4. Action

Also See, procedure call in compiler design

Static Allocation

The different steps involved in Static Allocation are as follows.

1. Implementing Call Statement

The following code is needed for implementing the call statement.

MOV #here + 20, callee.static_area   
GOTO callee.code_area

Where, 

callee.static_area  represents the address of the activation record.

callee.code_area represents the address for the procedure’s first function.

2. Implementing Return Statement

The following code is needed for implementing the call statement.

GOTO * callee.static_area  

Where, callee.static_area  represents the transfer of control to the address.

3. Implementing Action Statement

For implementing an Action statement, ACTION instruction is used.

4. Implementing Halt Statement

This is the final instruction for returning the control to the operating system.

Also See, Top Down Parsing

Stack Allocation

The different steps involved in stack allocation are as follows.

1. Initializing Stack Statement

MOV #stackstart , SP    /*initialization of stack*/  
HALT             

2. Implementing Call Statement

ADD #caller.recordsize, SP  
MOV #here + 16, *SP              
GOTO callee.code_area  

3. Implementing Return Statement

GOTO *0 ( SP ) /*returning to the caller */   
SUB #caller.recordsize, SP       

Frequently Asked Questions

What is an Activation Record?

The data required during the program's execution is stored in an activation record block. 

Name the different ways in which the address of the target code can be described.

Static Allocation and Stack Allocation

Name the different address statements associated with allocation and de-allocation of activation records.

The different address statements associated with allocation and de-allocation of activation records are:

  • Call
  • Return
  • Halt 
  • Action

Name the different steps involved in implementing the static allocation.

The different steps involved in implementing the static allocation are the implementation of call, return, action, and halt statements.

Name the different steps involved in implementing the stack allocation.

The different steps involved in implementing the stack allocation are the initialization of the stack statement and the implementation of call and return statements.

Conclusion

Congratulations on finishing the blog!! After reading this blog, you will grasp the concept of Run-time Environments.

Recommended Reading:

Do check out The Interview guide for Product Based Companies as well as some of the Popular Interview Problems from Top companies like Amazon, Adobe, Google, Uber, Microsoft, etc. on Coding Ninjas Studio.

Also check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc. as well as some Contests, Test Series, Interview Bundles, and some Interview Experiences curated by top Industry Experts only on Coding Ninjas Studio.

Cheers!

Live masterclass