You are on page 1of 12

RUN-TIME ENVIRONMENT

BY
GHULAM GHOSE 410
LIYA NAZEER 405
SO WHAT ARE WE TALKING ABOUT
HERE?
• How do your code and data look like during execution?
• Interaction among compiler, OS, and target machine
• The main two themes:
– Allocation of storage locations
– Access to variables and data
INTRODUCTION
• A program as a source code is merely a collection of text code, statements etc.
and to make it alive, it requires actions to be performed on the target machine.
• It needs memory resources to execute instructions.
• It contains names for procedures, identifiers etc., that require mapping with the
actual memory location at runtime.
• Runtime environment is a state of the target machine, which may include
software libraries, environment variables etc.
SOURCE CODE TO EXECUTION

C SOURCE COMPILER ASSEMBLY ASSEMBLER OBJECT FILE

LIBRARY
Linker

LOADER EXECUTABLE
DLL
RUN-TIME RESOURCES
• Execution of a program is initially under the control of the operating
system(OS).
• When a program is invoked:
– The OS allocates space for the program
– The code is loaded into part of this space
– The OS jumps to the entry point of the program
(i.e., to the beginning of the “main” function)
TYPICAL MEMORY SUBDIVISION
Low Address

CODE

Memory

Other Spaces

High Address
ORGANIZATION OF CODE SPACE

Usually, code is generated one function at a time. The code


area thus is of the form:
Code for fun 1 Entry point

Code for fun 2 Entry point

……

Code for fun n Entry point

It is the text part of a program that does not change at runtime. Its memory
requirements are known at the compile time.
ASSUMPTION ABOUT FLOW OF CONTROL

• Execution is sequential; at each step, control is at some specific program


point and moves from one point to another in a well-defined order.
• When a procedure is called, control eventually returns to the point
immediately following the place where the call was made.
• A procedure has a start and an end delimiter and everything inside it is
called the body of the procedure.
ACTIVATION RECORD

The execution of a procedure is called its activation. An activation record


contains all the necessary information required to call a procedure. An
activation record may contain the following units depending upon the source
language used
Temporaries, Local Data, Machine Status, Control Link, Access Link, Actual
Parameters, Return Value.
CONT…

Whenever a procedure is executed, its activation record is stored on the stack, also
known as control stack. When a procedure calls another procedure, the execution
of the caller is suspended until the called procedure finishes execution. At this
time, the activation record of the called procedure is stored on the stack.
When a called procedure is executed, it returns the control back to the caller. This
type of control flow makes it easier to represent a series of activations in the form
of a tree, known as the ACTIVATION TREE.
CONT…
To understand this concept, we take a piece of code as an example:
...

printf(“Enter Your Name: “);


scanf(“%s”, username);
show_data(username);
printf(“Press any key to continue… ”);
int show_data(char * user)
{
printf(“Your name is %s”, username);
return 0;
}
...
CONT…
Activation tree of the code given.

You might also like