Experiment no 7
Problem Statement: To Study & understand the working of
the linker.
Theory: Execution
of a program written in a programming language is achieved in the
following four steps:
- Translation: A program is translated into a target program.
- Relocation: Relocation is the action of changing the memory addresses used in the code of the program so that it can execute correctly in the allocated memory area.
- Loading: The program is loaded in a specific memory area for execution.
In the fig 5.1 we can see that Linker takes Object modules as an
input and gives out the Binary programs.
The syntax is as follows:
linker <link origin>,<object
module names> [,<execution
start address> ]
where,
<link origin>=memory address to be given to the first word of
the binary program.
<object module names>= name of OM as an input
<execution start address>= an optional part
Program linking is the process of binding an external reference to
the correct link time address.
An external reference is said to be unresolved until linking is
performed for it.
Linking is achieved using following two linking related concepts.
1. Public Definition (PD): A symbol defined in a
program unit that may be referenced in other program units. All PDs
are listed in the ENTRY statement.
2. External reference (EXT): A reference to a
symbol that is not defined in the program unit containing the
reference. All EXTs are listed in the EXTRN statement.
Let us see the example:
A program shown in Figure 5.2 contains only one public definition of
the symbol TOTAL as listed by the ENTRY statement.
There are two symbols listed in the statement EXTRN statement, we can
call that these symbols are externally referenced.
Program unit Q of Figure 5.3 contains a public definition ALPHA which
has the translation time address 231. Let Q be linked with the
program P of Figure 5.2
Program unit P contains as external reference to symbol ALPHA in the
instruction with translation address 518.
Let the linked origin of P be 900 and its size be
42 words. Hence the linked origin of Q is 942, and, accordingly, the
linked address of ALPHA is 973.
The external reference in the instruction with the translation time
address 518 in P is resolved by putting the linked address of ALPHA,
i.e., 973, in it.
Frequently
asked Questions:
1. Explain the fields of object module and binary programs.
2. Explain translated, linked & load time address.
3. Explain translated origin, linked origin and load origin.
4. Explain the need of ENTRY and EXTRN statements along with PD and
EXT concepts.
Comments
Post a Comment