0% found this document useful (0 votes)
103 views

Example, Showing Entries in Different Databases: Relocatable

The direct linking loader works as follows: 1. It builds object code segments in memory from the object files without relocation. 2. The assembler provides the loader with the length of each object code segment, a list of symbols defined in each segment, and a list of symbols used in each segment but defined elsewhere. 3. The loader uses this information to place each segment in memory and link them together to form the executable program.

Uploaded by

Ramiz Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
103 views

Example, Showing Entries in Different Databases: Relocatable

The direct linking loader works as follows: 1. It builds object code segments in memory from the object files without relocation. 2. The assembler provides the loader with the length of each object code segment, a list of symbols defined in each segment, and a list of symbols used in each segment but defined elsewhere. 3. The loader uses this information to place each segment in memory and link them together to form the executable program.

Uploaded by

Ramiz Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

(6) Direct Linking Loader

UQ. Explain the working of Direct linking loader with


example, showing entries in different databases
built by DLL MU-Dec. 17, May 18, 10 Marks

It is a type of relocatable loader.


The direct linking loader is the most common type of
loader.
The loader cannot have the direct access to the source
code.
And to place the object code in the memory there are
two situations: Either address of the object code could

be absolute or can be relative.

If at all the address is relative then it is the assembler


who informs the loader about the relative addresses.

The assembler should give the following information to


the loader
1. The length of the object code segment
in
2. The list of all the symbols which are not defined
the current segment but can be used in
the current

segment.
which defined in the
3 The list of all the symbols are

but can be referred by the other


current segment

segments.
26.8.1 BasicBlocks

Use following rules -

G) First statement is leader

(ii) Any statement that is the target of a conditional or


unconditional go to is a leader.

(ii) Any statement that immediately follows a goto or


conditional go to statement is a leader.
System
Sem 6 Comp)
Programming &CC (MU
4.1 INTRODUCTIONTO LOADERS (Loaders and Linkers)...Page no (4-3)
iv. Loading
Define Loader. MU
UQ
May. 19, 2 Marks Finally, executable file contents (i.e. machine
vQ What is
loader?
MU-Dec. 16, 2 Marks instruction and data) will be placed physically into
memory for execution.
Definitio : A loader is a system program which takes|
object code (i.e. machine code) as input that is loading into| MemoryY
Source Translator Object
for execution. program A e.g. assembler) programA
the memory
Loading of a progrianm invoives reading executable file
Linker LoaderObject program A

main memory. Source Translator Object Object program


disk
fromdisk to Responsibility of loader as part g.asembler)program B
operating system is loading a
program and libraries for Libraries
execution. After completion of loading.
operating system Fig. 4.1.2: Role of Loader
starts program execution by passing the contr to starting of
loaded program code.

Functions of Loader

Ua. Explain functions of loader.

MU-May 15, Dec. 16, May 17,May 18, Dec.18,


May 19, May 19 (New Syllabus), 5 Marks
UQ What are the different functions of loader?
MU Dec. 15, 5 Marks

Functions of Loader

i. Allocation

ii. Linkinng

ii. Relocation

iv. Loading

Fig. 4.1.1 : Functions of Loader

i) Allocation
Allocates memory space for program.

i ) Linking
Binding of object program code with necessary library
routines or other object program codes to generate
executable program code.
(lii) Relocation

changes the memory address of address sensitive


nstruction of program so that it can be loaded at an

address different from the location originally specified.

U-New Syllabus w.e.f academic year 21-22)(M6-70)


System Programming & CC (MU - Sem 6-Comp)
(Compilers: Synthesis
Phase)..Page no (6-24)
One node is
initial; the block whose leaderis
the
(2) Algebraic transformations statement.

Consider statements There is directed edge from block B to block B if B


X = x +0 can immediately follow B in some
execution
sequence; i.e. if
or X =x *1
1.There is a conditional or unconditional jump from
can be eliminated from a basic block without changing
the last statement of Bj to first statement of B, of
set of expressions it computes.
B immediately follows Bj in the orderof
Replace expensive operations by cheaper ones 2 he
program and B does not end in an unconditional
e.g X y ** 2
requires funetion call to implement and can be replaced jump.
B is a predecessor of B2 and B2 is a successor of
by the cheaper.
B1
X: y *y
Prod: 0
6.8.3 Flow Graphs i:=1

GQ. What isa basic block and flow graph? Generate t1:=4
three address code for the following program. Find t2: a [t1j
the basic blocks in it and write flow graph for the t3: 4 * i
same (8 Marks) t4: b [t3]
15: t 2 t4
begin t6:= prod +t5
prod 0;
prod=t6B
i : 1; t7:i+ 1
do i =t7
begin if i< 20 goto B2
prod= prod +ali] * b[il:
i:=i+1;
end (1E1)Fig. 6.8.1: Flow graph for dot product program
while i <=20
6.8.4 Representation of Basic Blocks
end
Basic block can be represented by a record consisting
Flow graph is a directed graph used to add flow-of
of a count of the number of quadruples in the block followeu
control information to the set of basic blocks making
or
by a pointer to the leader of the block and by the lists
up a program.
"
predecessors and successors of the block as shown
Nodes are the basic blocks.
Fig. 6.8.1.
9
S y s t e mP r O g r a m m i n

(Loaders and Linkers)...Page no (4-21)


4.8 DIFFERENCEBETWEEN LINKING LOADER AND LINKAGE EDITOR

Ua. Linking
Compare Lin loaderand Linkage Editor.
are
***
-- --- MU-Dec. 18,5 Marks
Parameter
Linking Loader Linkage Editor
Performs all
linking and relocation operations, Produces a Linked version of the
F u n c t o n

program, which
including automatic library search, and loads thelis normally writen to a file or library for later
linked program into memory for execution.
execution.
Suitable for Suitable when a program is reassembled
for|Suitable when a program is executed many times
nearly every execution.
without being reassembled.
of
ecnlution
Reso
reference
eteriaResolution
of external reference and library Resolution of external reference and
library
ence and librarysearching is performed more than once.
and
searching is performed only once.
searching

finking operations|Linking loaders perform linking operations at|Linkage editors perform linking operations before
Linking
load time.
tume the program is loaded for execution
The relocating loader loads the load module into
Need of relocan8There is no need of relocating loader.
loader
the memory
Passes required The Loading may requires two passes. The Loading can be accomplished in one pass.
the program development is finished or|
Time of use When program is in development stage then at|.|When
when the library is built then linkage editor can be|
the linking loader be used.
that time can
used.

Diagram Object
program(s)

Object
program(s).
Linkage
Library editor

Linking
Library loader Linked
program

Memory
Relocating
loader

Loader
Fig. 4.8.1 : Linking
Memory

Fig. 4.8.2 Linkage Editor

Chapter Ends..
(5) Relocating Loader (BSS)

Ga. Explain transfer vector and relocation bit w.r.t. BSS


Loader and compare BSS loader with absolute
loader. (6Marks)
Definition : Loaders that allow for program relocation are
called relocating loaders/relative loaders i.e., it loads a
program in specitic area of memory, relocates it so that it|
can execute correctly.

To avoid possible reassembling of all subroutines when


a single subroutine is changed and to perform the tasks of
allocation and linking for the programmer the relocating
loaders is created.

Algorithm for Relocating Loader


Loader
(1) Compile and Go

GQ Explain Compile and Go' Loader scheme with


advantages and disadvantages using
suitable
diagram.
4 Marks)

and Go Loader is of the loader in which


A Compile one

assembler lies in memory and loader itself does the


machine instructions
process of assembling and loading
and data at specified memory locations.
Sem 6 Comp)
SystemProgramming &CC (MU
its machine code
Instructions are read line-by-line,
the at some mory
generated and directly put in
me

known address.
After completion of assembly process, assembler

address of the program to the location


assign starting
counter.

Source. Compile and- go Program


Pgm translator

Assembler

Compile and go Memory


assemble and go

Fig. 4.1.4: Compile and Go loader

Advantages of Compile and Go loader


Following are the advantages of Compile and Go loader
1. Implementation is simple.
2. Since assembler is present in one part of memory and
loader only loads the machine instruction directly at
designated address in memory.
3. No additional routines are
required to load the
compiled code into the memory.
4. Execution speed is generally much superior to
interpreted systems.
Disadvantages of Compile and Go loader
Following are the disadvantages of Compile and Go loader:
1. Wastage of memory because assembler occupies some
part in memory
2. Object file is not produced since source code is directly
converted into executable form and loaded into
memory.
3. User's program has to be reassembled every time it is
run.

4. Difficulty in handling if the source programs are in


different languages.
5. The execution time will be more in this scheme as
every time program is assembled and then executed.
6. It cannot handle multiple source programs or multiple
programs written in different languages. This is
because assembler can translate one source language to
other target language.

(MU-New Syllabus w.e.f academic year 21-22)(M6-70)


6.2.1 Quadruples
Each instruction in quadruples presentation is divided
into four vital fields

(1) Operator (2) argl


(3) arg2 (4) result.

Example: Consider expression a = b* - c +b* - c.

The three-address code is


t2 b * tl
tl = uminus c

t3= uminus c t4 b* 13
5 = t2 + t4 a = t5

# OpArgl Arg2 Result


(0)uminus C t1

(1) tl b 2

(2) uminus C t3

(3) t3 b t4

(4) + t2 t4 5

(5) t5 a
+
hatand Falllu laallM
1 E TE
F+TEE
T FT'
T E
T FTE
F E)id T

lauaid
E tE
t, 2,9
T,EP,$
F 1C,d , t,2,$
Dynamic Loading
It is necessary that the entire program and all data of a
to
process must be in physical memory for the process
execute.

To obtain better memory-space utilization, we can use

dynamic loading.
O With dynamic loading, a routine is not loaded
until it is called.

O All routines are kept on disk in a relocatable load

format.
O The main program is loaded into memory and is
The
executed. When a routine needs to call another
routine, the calling routine first checks to see

whether the other routine has been loaded.


o If not, the relocatable
linking loader is called to
load the desired routine into memory and to
update the program's address tables to reflect this
change.
O Then control is passed to the newly loaded
routine.

Advantages of Dynamic Loading


1. The advantage of dynamic loading is that an unused
routine is never loaded.
2. Dynamic loading does not require special support from
the OS.Operating systems may help the programmer,
however, by providing library routines to implement
dynamic loading.
5.2.7 Code Optimization
intermediate
code is
In code optimization phase
the
different optimization
improved by optimizing it using
concern about timee
techniques. In coding we always
the optimized code requires
and space complexities,
and as compared to
unoptimized code.
less time space

code optimization should be independent of the


The
machine architecture on
which program will be M
we can
executed. There are variousstrategies by which

optimize code, we will these in chapter 6.

of intermediate code generation followed


An algorithm

by code optimization is a wise way to generate good


The optimizer can reduce the conversion of
target code.
can be done once only
2 from integer to floating point
into float operation can be
at compile time, so the
eliminated by replacing the integer 2 by the floating-
point number 2.0.
Furthermore, ta variable also not needed as addition
result of t +id2 is stored in
tz and then in next
statement this value is assigned to id3.

We can directly assign result of addition to the ida


doing so temporary variable t and tt3 will not be
required, directly could be done by shorter sequence.
*
ids* 2.0id3
id3= id2 +t

You might also like