0% found this document useful (0 votes)
9 views19 pages

SS 4,5

The document discusses the roles and functions of loaders and linkers in computer systems, detailing various types of loaders such as assemble-and-go, relocating, absolute, and direct linking loaders. It outlines the processes of loading, linking, and relocating programs in memory, as well as the advantages and disadvantages of each loader type. Additionally, it explains the steps a loader performs to execute a program and the significance of relocation in memory management.

Uploaded by

eldhobenyamin84
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)
9 views19 pages

SS 4,5

The document discusses the roles and functions of loaders and linkers in computer systems, detailing various types of loaders such as assemble-and-go, relocating, absolute, and direct linking loaders. It outlines the processes of loading, linking, and relocating programs in memory, as well as the advantages and disadvantages of each loader type. Additionally, it explains the steps a loader performs to execute a program and the significance of relocation in memory management.

Uploaded by

eldhobenyamin84
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/ 19

(Module 4)

Loader C51
50 Semester TP Solved eries (System Softwar Liskea
r n
and
B.Tech. Fifth loader and
KTu the role of both linker:
4.3 shows to re-translate the user's program every
P i g u r e

t itime
s necessary
it is run.
Module 4 S u n c e
Pmgralm
tProgran

Assembier >0bject-> Linker


Executable
Object
Program

5)
4)
tis very difficult to handle multiple segments.
t is very difficult to
programs.
produce orderly module
Code Ready or
Execution
Loader
Ques 5) Discuss relocating
advantages and disadyantages.
loader with their
Linker and Loade.
Memory Ans:
Role
of Both Loader and Linker Relocating Loader (Relative Loader)
Tigure 4.3:
Discuss aassemble-and-go loader with their
The heart of a linker or loader's actions is relocation and
Step 5: Initializes the machine registersinc
ncluding h Discuss
ssen
code modification. The process of modifying the addresses
LOADER AND LINKER stack pointer
4)
QDesntages and disadvantages. used in the address dependent instructions of a program
Ans: Assemble-and-Go Loader Such that the program can execute from any allocated area
Ques 1) What is loading and linking? to a start-up routine that one in which the assembler
of the memory is called Program Relocation. oaders
Step 6: Jumps the stack S the ble-and-gO
loader is
argumenis from performing such a task is called relocating loader. As part
Or program S As the process of compiling and then places the
Define terms: and calls the progralm s main routine. BIsters of the loading process, the loader modifies the object code
jselt u nstructions in the designated memory
i) Loading 5sembled assembilng procesS 1s done first and then
to retlect the actual addresses assigned. Relocating loaders
i) Relocation Types of Loader ations. The are versatile when compared to the absolute loaders, when it
cembler causes a transrer the first instruction of
toO
ii) Linking 1) Assemble-and-Go Loader Comes to re-assembling routines every time when a single
gram. This loading scheme, is also known as routine is changed.
Relocating Loader (Relative Loader) the Pbler-and-Go.The loader here has just one
Ans: Loading and Linking 2)
Loader) instruction that
directs the loading of the newly assembled
Advantages of Relocating Loaders
The Source
Program written in assembly language or hign 3) Absolute Loader (Bootstrap memory. For example, WATFOR
level language will be converted to
object program, which de into the 1) Program can be loaded and executed in different parts
15 1n the machine language form for execution. This 4) Direct Linking Loader FORTRAN Compiler of memory irrespective of the address.
2) Relocation is done by the usage of relocation bits.
conversion either from assembler or from compiler,
contains translated instructions and data values from the Ques 3) What are the basic functions of a loader Compile and
3) Allocation is done by the availability of program length.
Go Program
sOurce program, or specifies addresses in primary memory (2020[03) Source
Translator, Loaded in
4) Linking is also done, as a part of the loading process
itself.
to be loaded for execution. This Program Memory
where these items arethree Ans: Basic Loader
Functions e.g 5) Loader performs all the four functions given below:
contains
1
the following processes, and they are, A loader is a system program that pertorms the loadimg
Assembler
i) Memory allocation,
Loading: It allocates memory location and brings the
object program into memory for execution - (Loader)
function: It brings object program into memory and start
ii) Subroutine linkages,
its execution. The role of loader 1S as snown in the figure
iil) Relocation, and
2) Linking: It combines two or more separate object 4.1:
ASsembler
iv) Loading of code into the memory.
programs and supplies the information needed to
Figure 4.4: Compile and Go Loader
allowreferences between them -(Linker)
Object Loader Object Disadvantages of Relocating Loaders
3) Relocation: It modifies the object program so that it Source-ransia"
Program Program TOgr Advantages of Assemble-and-go loader 1 The complexity of the loader increases with the
can be loaded at an address different from the location 1) Itis relatively easy to implement. capability to handle larger number
program SIze and
originally specified - (Linking Loader)
Exccui0n 2) Involves no extra procedures. of subroutines.
increased overhead on as there is
2) There is an memory
Disadvantages of Assemble-and-go loader increase in number of subroutines.
Ques 2) What is loader? List the various steps of 1) A portion of memory is wasted.
loader. Also list the various types of loaders. Figure 4.1: Role of Loader
Memory Discuss bootstrap loader (absolute loader) with their advantages and disadyantages.
Ans: Loader Ques 6)
Translator may be assembler/compiler, which generates
A loader is a utility of an operaling system. It copies the object program and later loaded to the memory by the Ans: Absolute Loader (Bootstrap Loader)
programs from a storage device to a computers The absolute loader is the simplest of all the loaders.
loader for execution.
main memory. where the program can then be executed 0000 Absolute 0000 Relocatable
Loader perfoms the loading function. It is responsible for In figure 4.2 the translator is specifically an assembler, 00FF Toader
00EE loader
initiating the execution of the process. which generates the object loaded, which becomesinput to
0100
the loader
Various Steps a Loader Performs 0110
Loaded
The various steps required for working of loader are as BRA 0110
follows: Source Object 01FO - - - - -
progran 4100
rogram
Assembler Dject Loader 4110 ------:
determine the
Step 1: Read executable file's header to Program Program
Ready 1or
01FF
BRA4110
Relocatable
size of text and data segments. program
Execution 41FE
Step 2: Create a new address space for the program
Step 3: Copies instructions and data into address space FFFFL
FFER (b)
the program the Figure 4.51 Memory Map
Step 4: Copies arguments passed to on
Figure 4,2: Role of Loader with
Memory
stack.
C-52 TP Solved Series (System
ed Serics(System (odule 4)
C-53
SotWare) kn
(Modu
Semester
B.Tech, Fifth
L o d e r

and

lt can linking ader


loader with thelr
Linker
for an absolute loader,
read a machine
language Ques 8)
Discuss direct Designa na algorithm The advantage of absolute loader is simple and cfficient
backup storage and place it in program
from the specifieu advantages a n d disadvantages,

Loa
(2019 03]) But the disadvantages arc, the need for programmer to
determined address memory starting fromap Absolute Loader
(figure 4.5). The machine ns: Design
ol
Desn of absolute loa an
loader is very simple. The object Specity the actual address, and, difficult to use subrouline
program so loaded will work langug Ans: Direct
Linking
Loader
: Or
absolute

libraries.
starting from the specified corectly only if it is loadea
address. Absolute type or
A direct Jinking loader 1S a general relocatableload
an The
operilo
oaded to specitied
locationsiin the memory. At the
loader is most popular
sCheme presentl is der jumps to the specitied address to begin
impractical, as there are lots of is perhaps the d The algorithm for this type of loader is given below. The
involved in loading the complieations
program. "Bootstrap loader 1s an allows programming
muluple procedure seo the O the loaded program. The role of absolute
Object program and, the object program loaded into
example of absolute loader. This gives the a
progan execulion
in the figure 4.6: memory by the absolute loader are also shown. Each byte
data segment.
s h o w n i

multiple mon s as

there is no need to referen lander


of assembled code is given using its hexadecimal
convenience, since
Advantages of Absolute Loader n other Segment. Thicla or Absolute|1000
Object representtior in character form which is casy to read by
instructions present
1) The absolute object Loader
loader simply performs input and output flexible reference hile aOvide
and accessing ability, while at the Program human beings
operation to load a accessing ability same Progra Ready for
program into the main memory allowing independent
2)An absolute loader is coded in time
loader thacthe
Execution Each byte of object code is stored as a single byte: Most
very few machine assembler gives the
instructions. program.
The
2000 machine store object programs in a binary form, and it is
5) Program is stored in the information: necessary that file and device conventions do not cause
library in their ready-to of the segment.
execute form. Such a library is called a Phase 1) The length Some of the program bytes to be interpreted as control
A list of all symbols
the
segment
im thaf Memory
Library. 2) and their relative b e Role of Absolute Loader
characters.
referenced by other segments Figure 4.6:
Disadvantages of Absolute Loader Within the segment.
location Loader
a n Absolute
3) A list of all symbols that are not defined in the for
1The programmer must explicitly specify the assembler Algorithm
referenced in the segment.
the memory where the program is to be loaded. segment but begin
read Header record
4) Conveys the entry pont oI the program ich is to
2) Handling mulkple subroutines become difficult and length
ne programmer must specify the address of the
since know where the loader
is to transter the control
and
verify program
name

loaded. Text record


when the instructions are read first
routines wherever they are referenced to perform record type E' do
while
subroutine linkages. The assembler does not provide its own symbol t begin code to location in
3) When dealing with lots of subroutines the manual if object code is in character form, convert into intemal representation) move object specified
the loader. The assembler provIdes TolloWing types
of next obJect program record
shufiling and re-shuffling of memory address cards in the object (deck). memory read

references in the routines become tedious and 1) External Symbol Directory (ESD): It provides end
address specified in End record
One byte
charncter
complex. information about all symbols defined and used in t jump to
source program. It is basicaliy a symbol dictionaryor end H.COPY 001000,00107A
Ques 7) Given an idle computer with no program in look-up. This is the symbol table. T,001000,1E,141033,482039,001036,281030,301015,482061,3C1003,00102A,0C1039,00102D
memory, how do we get things started? 2020[03]) T00101E,15,0C1036,482061,081033,4COO00,454F46,000003,000000
2) Text (TXT): It contains the actual translated object
code, non-relocated data, initial values and so on. T002039,1E,041030,001030,E0205D,30203F,DS20SD,281030,302057,549039,2c205E,38203F
Ans: In this situation. with the machine empty and idle,
T002057,1C,101036,4C0000,EL,001000,041030,E02079,302064,509039,DC2079,2C1036
there is no need for program relocation. We can simply 3) Relocatable and Linkage Directory (RLD):
T,002073,07,382064,4CO000,05
specify the absolute address for whatever program is first contains information about address sensiti
loaded. Most often, this program will be the operating E,0O1000
instructions in the source program. They need to be (a) Object Program
system, which occupies a predefined location in memory. relocated as performed in relocating loader
Memory address Contents
This means that we need some means of accomplishing 4) End (END): It signifies the end of the object deek
the functions of an absolute loader. This is the last card in an object deck.
0000 x XX X**XXXXXXXXXX XXXXXXXXXXXX XXX
0010 x xxXAXXX XXXX X*XX
Some early computers required the operator to enter into
memory the object code for an absolute loader, using Advantages of Direct Linking Loader AX
1) It provides the programmer with multiple procedure OFFO X XXX XXXX XXXXXXXX X XX XX X XX X*X
switches on the computer console. However, this process 10001 4 I 0334 8 2039 0010 36281 0 30 3 01014 SHalf
segments & multüple data segments. 00 I 0 200e T 0byte
is much too inconvenient and error-prone to be a good 1010|206 1 3CI0 0300I02A 0CI039
2) It provides endorsement referencing& accessing ability 8 2061 08IO334C 0000 4 3
O 0000 cOpY
solution to the program. 102036 4
3) It allows independent translations of programs along X *XXX XX* XXXX AXX AAA

1030 10 0 0 0 00XX
with above benefits.
On some computers, an absolute loader program is
resident in a read-only memory (ROM). O 30 0010 3 0E 0
permanenuly
XXXXX*XXXxO4T

XX XXXXX
Disadvantages of Direct Linking Loader 2030X 28103 0 30 2 0 5 7 5 490
When some hardware signal occurs (for example, the 3FD8 2 05D
D3020
The linking and loading need to be postponed until the 2040 |2 0 5 0 0 F 1 o01
1036 4 CO0 0
operator pressing a "system start switch), the machine execution. During the cxecution if at all any subroutine is
2050 3 9 2 C205 E 38203 FI0 39 DC20 79
2060 0 00 4 1030 E020 7930 20645 0 9 0
begins to execute this ROM program. On some computers, TX

the program is executed directly in the ROM; on others the needed then the process of execution needs to be 20702 CT0 36 38 20 64 4C0 0 000 5X X X

XXX AX A XI XIA
from ROM to main memory and
Suspended until the required subroutine gets loaded in the 2080 x XX*X XXX
XXXXX*X*

program is copied
main memory.
executed there
(b) Program Loaded in Memory
However, some machines do not have such read-only Ques 9) Discuss the design of absolute loader,
4.7: Londing ot an Absolute Program
inconvenient to change a Or Figure
storage. In addition, it can be the End record is encountered,
the
ROM program if modifications in the absolute loader
Give the algorithm for an absolute loader. (2017 (03) Text record is read to memory. When
Header record is first checked. Then, cach
are
The
Or
required. loader jumps to the specificd nddress,
SUbrouune iorcut Line Mnchine
Ans: Lnbel Instruction
In our
Object Program Format i) Most such libranes contain man Number Address Operand
object subroutines than will be used Objeet
given using itsprogram. each byte of
by any more
one 5 0000 COPY
START Code
hexadecimal assembled code is program. 10 0000 FIRST 0 Relocatable program
form representation in character t) To make efficient use of memory, it is 0003
STL RETADR
17202D
exacuy impor
LDB
be able to select and load WLENGTH 69202D
For those
example, the opcode for STL that are needed. routines 15
--

BASE LENGTH
O000-- CLOOP.-ISUB.-_.-RDREC
represented by the pair of instruction would be
1)
When they are characters1" and 20 000A
LDA 4BIO1036---------
read
Dytes of memory and by
the loader,
they occupy two
Ques 12) Describe the machine dependent f e
loader.
ependent ieatures of 25 000D
0010
COMP
LENGTH
0
032026
290000
With hexadecimal must be stored in a 0

value 14. singly byte JEQ ENDFIL


Each pair of Ans: Machine Dependent Features of Loader 35 0013 33200 --
bytes from the object WRREC
must be
packed together into one program
record Features of machine dependent loader are as followe
0017
CLOOP ABIO105D.-------
3F2FEC
byte during loading. 1) Program relocation is an inalrect consequence
45 001A ENDFIL
LDA EOF
This method of of
change to larger and more powertul computers
0 001D STA
032010
representing an object program 1s
inefficient in terms of way relocation is implemented in a loader he
55 0020
LDA
BUFFER OF2016
space and execution time. 0023
13 O10003
dependent upon machine characteristics. lso 60 STA
Therefore, most machines store Use 65 0026 LENGTH OF200D
object program in a 2) Linking is not a machine-dependent function Modilication.
+JSUB_ WRREC
binary form Each byte of
object code is stored as a has the same implementation techniques for io t
recoras 0 002A
@RETADR
4B10105D---
3E2003
Single byte in the object The process of limking
B0 002D EOF BYTE CEOF
conventions should not cause program. The file and device usually involves relocation 95 0030
454F46
some of the routines being linked of RETADR RESW
bytes to be interpreted as
some of the
object program
control character.
together. 100 0033 LENGTH RESW
Ques 13) What is relocation2 105 0036 BUFFER RESB
For example, 4096
indicating the end of record with byte
a a
110
containing hexadecimal 00 would clearly be unsuitable Ans: Relocation 115
SUBROUTINE TO READ RECORD INTO BUFFER
for use With a
stored in
binary object program. Object program The concept of program relocauon is, the
execution of
120
binary form do not lend
themselves well to the object program using any part or tne 125 1036 RDREC CLEAR
pinting or
reading by human beings. Therefore, we
to
sufficient memory. The object program 1s
available and 130 1038
A B410
conunue to use character loaded into CLEAR A B400
representations of object memory wherever there is room for it. The 132 103A
programs in this course.
address of the object program 1s not
actual startino CLEAR B440
133 103C
time.
known until loa +LDT #4096 7510100
I35 1040 RLOOP TD
Ques 11) Discuss the issues INPUT E32019
related with absolute 140 1043
loader. JEQ RLOOP 332FFA
Relocation provides the efficient sharing of the
with
machine 45 1046 RD INPUT DB2013
Ans: Issues of Absolute larger memory and when several independent 150 1049 COMPR A,S A004
Loaders programs are to be run together.
S5 104B
1) On a larger and more advanced JEQ EXIT 332008
know in advance where a
machine, one does not 60 104E STCH BUFFER, XX
It also supports the use of subroutine 57C003
program will be loaded. libraries efficiently 65 1051 TIXR T
2) Eficient sharing of the machine Loaders that allow for program B850
wntes relocatable
requires that one
relocating loaders or relative loaders.
relocation are called 70 1053 JLT RLOOP 3B2FEA
programs instead of absolute one. 75 1056 EXIT STX LENGTH 134000
80 1059 RSUB 4FUO00
Ques 14) Explain various methods of
specifying relocation.Dr 185 105C INPUT BYTE XFI
195
With the help of an Algorithm, explain how relocation is done using modification bits and direct addressing with 200 sUBROUTINE TO WRITE RECORD FROM BUFFER
relocation bits.
205
Or 210 105D WRREC CLEAR X B410
What is the use of Bitmask in program relocation?
(2018[03]) 212 105F LDT LENATH 774000
Ans: Methods for Specifying Relocation 215 1062 WLOOPTD OUTPUT E32011
Two methods for specifying relocation in 220 1065 JEQ WLOOP 332FFA
object programs: 225 1068 LDCH BUFFER, X 53C003
) Use Modification Records: A Modification record is used to describe each part of the
changed when the program is relocated. object code that must be 230 106B WD OUTPUT DF2008
235 106E TIXR T B850
240 1070 JLT WLOOP 3B2FEF
Figure 4.8 shows a SIC/XE program to illustrate this first method of specifying relocation:
245 1073 RSUR 4FOQNO
The only portions of the assembled program that contain actual addresses are 250 1076 OUTPUT BYTE X'05'
the extended format
15, 35, and 65. Thus these are the only items whose values are affected relocation. instructions on lines 255 END IURST
by
Figure 4.8
Figure 4.9 displays the object program coesponding to the source in figure 4.8:
HCOPY 000000,001077 SUBROUTINE TO READ RECORD INTO BUFFERR
T,000000,ID,17202D,09202D,4B101036,032026,290000,332007,4B10105D,3F2PEC,O32010 2039
T,00001D,13,0P2016,010003,0F200D,4B1o105D,3E2003,454F46 30 203C
RDREC LDX
LDA
ERO 041030
T,001036,1D,B410,B400,B440,151010,E32019,332PFA,DB2013,A004,33208,57CO03,B850 135 203FF
RLOOP TD
ZERO
INPUT
001030
2042 ED20SD
T.001053,1D,312FEA,13400,4FO00),FI,B410,77400,E3201,32FFA,51C3,DF2008,B85 45 2045
E
RLOOP 30203F
T,001070,07,382FEF,4F0000,05 2048
S0
COMP
NPUT
ZERO
DS205D
281030
M000007,05+COPY 155 204B
JEQ EXIT 302057
M,000014,054COPY Modification 60 204E STCH BUFFER, X SHO39
M000027,051COPY records for+ JSUB 2051
2054
MANLEN
2C205E
E,O0000 RLOOP 38203F
75 2057 Er STX LENGTH 101036
Figure 49 obJect program corresponding to the source in figure 4.8 180 205A RSUB CD000
8S 205D INPUT BYTE
Ench Modification record specifies the starting address and lengthi of the freld wnose vialue 15
to be altered, It the Begin a necw 20SE MAXLE WORD 4096
F
describes the modification to be performed. In this example, all modifications add tne value
o the symbol COpy
Text record 001000
which represents the
starting address of the program (igure 4,10).
SIC/XE Relocation Loader
Algorithm SUROUTNE TOWRITERECORDIRONIBUEER
begin 2061 WRREC LDX ZERO 041030
get PROGADDR from operaling system 2064 WLOOP 1D OUTPUT
while not end of input do 20 2067 JEQ WLOOP
EDEO
302064
hegin 225 206A LDCH BUFFER. X SO9039
read next record 30 206D WD OUTPUT DC2079
while record type z 'E do 35 2070 LENGTH 2C1036
begin 2073 LT WLOOP 382064
4S 2076 RSUB 4C0000
read next input record
230 2079 OUTPUT BYTE X05 05
wliile record type = "T tlien
END FIRST
begin
move object code from record to location Figure 4.11
ADDR +Specified nddress
This is a relocatable program WriRen for the standard version of sIc. The important difference between this
end
wliile record type = "M example and the one in igure 4.8 is that the standard SIC machine does not use relative addressing. In this program
add PROGADDR nt tlhe location PROGADDR + the addresses in all the instructions except RSUB must be modified when the program is relocated. This would
specified address require 31 Modification records, which results in an object program more than twice as large as the one in figure
end 4.9
end
end 2) Use Direct Addressing with Relocation Bits: On a machine that primarily uses direct addressing and has a fixed
Figure 4.10: SIC/XE Relocation Loader instruetion fomat, it is often more efficient to specify relocation using a different technique. Eigure 4,12 show this
Algorithm
The Modification record scheme is a convenient means for method applied to SIC program example:
suited for use with all machine architectures. For
specilying program relocation; however, it is not well Data content. No
example, consider the program in figure 4.11. No modificaion s
nceded for RSUB
modification is
Line
peeded
Machine Label Instruction Operand
Number Address Objecet
1000 COPY START
Code H_COPY 0000D,00107A
10 1000 FIRST STL 1OO0
RETADR
Starting addres
141033
T.000000,1EFRC,140033,4S 1039,0p36,280030,3000 15,4S1061CoO03, 002A,OCUO39,0002D
15 1003 CLOOP JsUB RDREC 482039 T,00001E, 15,E0,OCO36,481061,080033,4C00),AS4F6,00003,00000
0 1006 LDA LENGTH 001036 105D,30103F,DS105D,250030,301057,548039,2C105E,38103F
5 TO09 COMP ZERO
T.001039,1E,FHC O4030,000030 ED
51030
100C JEQ ENDFL 1 301015 T.001057,04.o, 100036,4C001,00
0
100F JSUB WRREC 482061 T,001061,19/eED,040030.E01079,301064,3N9.DCI0792C0036,3810644C000,05
40 1012 CLOOP SCI003
1015 ENDFIL LDA EOF 00102A E,000000
0 1018 STA BUFFER Each relocation bit is
OCIO39 Ifit were placed in the
101B LDA THREE Bit mask: Cach associated with a 3-byte
60 101E LENGTH
00102 relocaton bit is
preceding Text record, it
ment of object code in
OC1030 would not be properiy algncu
65 1021 JSUB WRREC asocialed with cach to correspond to a relocation theText recoro
482061
0 1024 word of object code bit because of the 1-byte data
LDL RETADR
75 1027
RSUB *---
0S1033 value from Line 185.
80 T02A EOF BYTE CEO 4C0000
85 102D THREE WORD with Relocation Bits
000003 Figure 4.12: Object Program
90 1030 ZERO ORD 000000
relocation bit
1033 RETADR RESW before except that there is a
-----
records the same as
Modification records. The Text
are
100 1036 LENGTH RESW Lnere are that there is one
instructions occupy one word, this
no means
T05 1039 BUFFER RESB 4096 SSOCiated with each word of object code. Since all SIC bits are gathered together
into a bit mask folloWing the
relocation
I10
OCalion bit for each possible instruction. The
C-60 LoIder
(iodurc
4) C-61
TP Solved Series and
B.Tech, Fifth Semester (System Linker
Software) KT Define the data structure for linking loader.
2) EXTREF (External Reference): The EXTREF Dues
17)
Or
For example, ESTAB
PROGB, and PROGC)
(refer three programs PROGA,
given is as shown below. The
statement names
control
symbols used in this
(present) Vhat is ESTAB?
ESTAB has four entries in it; they are name of the control
section and are defined elsewhere. For 0040 LISTA EQU
Or section, the symbol appearing in the control section, its
example, EXTREF RDREC, WRREC data structure used for the linking loads address and length of the control section.
EXTREF LISTB, ENDB, LISTC, ENDC 0054 ENDA EQU Describe the
(2017 [2.51)
0054 REFN WORD
ENDA-LISTA+LISTC 000014
algorillin.
Or Control SectionSymbolAddress Length
Implementation of EXTDEF and EXTREF 0057 REFS WORD ENDC-LISTC-10 passes in
PROGA 4000 63
ENDC-LISTC+LISTA-1 PFFF6
for having two linking
luctify the need
a
The assembler must include informmation in the 005A REF6 WORD LISTA 4040
object 005D REF7 WORD ENDA-LISTA-(ENDB- r 1llustrate the data structures usedin for a ENDA
ENDA 4054
program that will cause the loader to insert proper values C00014 PROGB
LISTB) loader, showing now are
they used each 4005
where they are
required
in the form of linking
and, Refer record(R). Define
record (D) 0060 REF WORD LISTB-LISTA (2019[04]) LISTB 400
REFI
FFFCO pass. ENDB 40D3
1) Define Record: The fomat of the Define record END PROGC 40E2
(D) Two Passes in Linking Loader
along with examples is as shown here: Ans: Need for LISTC 4112
Col. I D Program Linking Example (PROGB) The algorithm for
a
linking loader is considerably more ENDC4124
Col. 2-7 Name of external 0000 PROGB START 0 complicated than the absolute
loader
algorithm. The input
symbol defined in this
EXTDEF LISTB, ENDB
of a set of
loader consists object programs (i.e., Use of Data Structure in Pass 1
control section to such a
to De linked together. It is During the first pass, the loader is concerned only with
Col 8-13Relative address within this control section EXTREF LISTA, ENDA, LISTC, control sections) h a t are
to make an
(hexadecimal) ENDC
possible (and common) for a control section Header and Define record (ypes in the control sections.
Col. 14-73 Repeat information in Col. 2-13 for external reference to a symbol whose definition does not The beginning load addresS for the linked program
other external symbois ******** until later in this input stream. (PROGADDR) is obtained from the operating System.
appear
Example Records
0036 REFI +LDA LISTA
03100000
This becomes the starting address (CSADDR) for the first
003A RER2"LDT LISTB+4
77/2027 In such a case the required linking operation cannot be control section in the input sequence. The control section
DLISTA 000040 ENDA 000054 003D REF3 LDX the external name from the Header record is entered into ESTAB, with
#ENDA-LISTA 05100000 performed until an address is assigned to
DLISTB 000060 ENDB 000070 alue given by CSADDR. All extermal symbols appearing
symbol (that is, until the later control section is read).
its in the Define record for the control section are also entered
2) Refer Record: The format of the Refer record (R) Thus a linking loader usually makes two passes over
0060 LISTB EQU input, just as an assembler does. In terms of general into ESTAB. Their addresses are obtained by adding the
along with examples is as shown here:
function, the two passes of a linking loader are quite value specified in the Define record to CSADDR. When the
Col 1 R 0070 ENDB EQU End record is read, the control section length CSLTH (which
Similar to the two passes of an assembler:
Col2-7 Name of external symbol refered to in this 0070 RE WORD was saved from the Header record) is added to CSADDR.
control section O073 REFS
ENDA-LISTA+LISTC 000000 1) Pass I assigns addresses to all external symbols
WORD
ENDC-LISTC-10 FFFFF6 2) Pass 2 performs the actual loading, relocation and This calculation gives the starting address for the next
Col. 8-73 Name of other extermal reference
symbols 0076 REF6 WORD ENDC-LISTC+LISTA-1 FFFFPF Tinking.
control section in sequence. At the end of Pass I, ESTAB
0079 REF7 WORD contains all external symbols defined in the set of control
Example Records ENDA-LISTA-(ENDB- FFFFFO
sections together with the address assigned to each. Many
R LISTB LISTB) Data Structures for a Linking Loader
ENDB LISTC ENDC O07C REF8 WORD LISTB-LISTA loaders include as an option the ability to print a load map
000060 The algorithm for a linking loader is considerably more
RLISTA ENDA LISTC ENDC END This
RLISTA ENDA LISTB ENDB
complicated than the absolute loader program. The that
shows these symbols and their addresses.
information is often useful in program debugging.
concept given in the program linking section is uscd for
Program Linking Example (PROGC) The
Here are the three programs named as
and PROGC, which are separately assembled and each of
PROGA. PROGB
000 PROGC START 0
0eveloping the algorithm for linking loader. Use of Data Structure in Pass 2
modification records are used for relocation so that the
EXTDEF LISTC, Pass 2 of our loader performs the actual loading
which consists of a single control section. LISTA., ENDA unKIng and relocation functions are performed using the CSADDR is used
in PROGA. LISTB, ENDB in PROGB and LISTC, ENDC ENDC relocation, and linking of the program.
in PROGC are external definitions in each of the control EXTREF LISTA. ENDB, sane mechanism. Linking loader uses twO-passes logiC: in the same way it was in Pass 1-it always contains
the
ENDB
LISTB, Fass 1: Assign addresses to all external symbols.
actual starting address of the control section currently
sections.Similariy LISTB. ENDB, LISTC, ENDC in
PROGA LISTA. ENDA. LISTC, ENDC in PROGB, and
Pass 2: Perform the actual loading, rclocation, and linking.
loaded. As each Text record is read, the object code
being curent value ot
LISTA. ENDA. LISTB, ENDB in PROGC, are external ESTAB (External Symbol Table) is the main data is moved to the specified address (plus the
0018 REFI +LDA 03100000
references. These sampie programs gven here are used to LISTA CSADDR). When a Modification record is
encountered,
001C REF2 LDT 77100004 siructure fora linking loader:
illustrate inking and relocation The following figures LISTB+4 ) It is to store the name and address of each external the symbol whose value is to be used for
modification is
O020 REF3 +LDXX
give the sumple programs and their coresponding object #ENDA 05100000 looked up in ESTAB. This value is then
added to or
LISTA symbol. subtracted from the indicated location in memory.
which contain D and R records along
with other
programs, 4ti5 similar to SYMTAB in the assembler,
records. 0030 LISTC EQU section the symbol 15
tindicates in which control 1 of
Ques 18) Deseribe the program logic for pass
defined. londer. Also write its algorithm.
Program Linking Example (PROGA) 042 ENDC EQU linking
0042 REF4 WORD 000050 4A hash organisation is typically used for this table.
5) Two
Or
linking loader.
o000 PROGA START ENDA variables
defined: are Give the algorithm lor pass I of the
EXTDEF LISTA ENDA 0045 REFS WORD LISTA+LISTC PROGADDR (Program Load Address); (2020[04)) (2017 [2.5)
oo08
EXTREF LISTB ENDB, LSTC ENDC-LISTC the address in memory where Or
ENDC 10 Indicate beginning
0045 REF6 WORD be londed, Its value is for Pass 1 ot Linking Loader.
ENDC 00001 e inked program is to Explain the algorithm (2018 [06)
Supplied to loader by the operating system,
O04B REPT WORD LISTCHLISTA-1 1
ENDA LISTA 1) CSADDR (Control Section Address): Contain Ans: Program Logle for Pass
0020 REFI LDA LISTA 03201D to all extemal symbols. The
(ENDE-LISTB) Pass 1 assign addresses
0023 REF2 LDT LISTB+4 771094 04E REPE WORD 0000 e assigncd to the control
Starting nddress Used during passare,
LISTB-1LISTA tho loader, variables and Data structures
0027 REF3 DX #ENDA-LISTA o59014 END becion currently being scanned by
B.Tech, Fifnh Semester TP Soved Series (Module 4)
(System Software KTU
and
Loader
C-63
PROGADDR (Program Load
Linker
(Control Section Address) from OS. CSADDR begin for l'ass 2 ofLinking Londer
else if record type
Address), CSLTH (Control search ESTAB Algorithm 2 of 'M then
Length) and ESTAB. The Section for
symbol name The algonthmm
for Pass Linking Loader is given IModification record
Record. In Pass the loader pass 1 processes the Define
1.
if found then
begin
is concemed
and Define record only with Header set error flag
(duplicate extemal elow search ESTAB for modifying
1) Initialisation
types in the control sections: symbol) tO PROGADDR 5ymbol name
set CSADDR
else to PROGADDR if found then
1) The beginning load address for the linked set EXECADDR
add or subtract symbol value
program (PROGADDR) is obtained from the
enter symbol into
ESTAB with while not end ofinput
begin
do
Each iteration processes one control section at location
value
Operaing system. read next input record (Header record) (CSADDR +specified
)
Thisbecomes the starting address
(CSADDR) for
(CSADDR + indicated
address)
set CSLTH to control Section length 1ddress)
the first control wlile record typ * "E' do else
section in the input sequence end [for) set error flag (undefined
2) Record Scanning end {while 'E] begin
IIreach End record read nextinput record xtemal symbol)
1) The control section add CSLTH to CSADDR IStarting end (if 'M')
name from the Header record if record type = "T then text record
is entered into
ESTAB, with value given by nextcontrol section 1 address for begin end (while # 'E)
CSADDR end {while not EOF) if object code is in character is specified (in End record) then
ifan address
) All external set EXECADDR to (CSADDR + Sspecificd address)
symbols appearing in the Define end {Pass 1 1orm, convert into internal
IEnd record: transfer address is specified
Tecord for the control section are also representation
entered into add CSLTH to CSADDR IIMove to next
ESTAB. Ques 19) Describe the program logic
move object code from record to
CS
linking loader. Also write its algorithm. for pass 2 of
111) Extermal location
symbols addresses are obtained end (while not EOF
adding the valuc specified in the Define record by Or (CSADDR + specified jump to location given by EXECADDR (start execution of
CSADDR (Specified address to Give the
address)
loaded programj
+CSADDR).
iv) When End record is read, the algorithm for pass 2 of a linking loader. end (if T)
end (Pass 2)
control section
length CSLTH (obtained from Header record) iss (2019[04)
added CSADDR to calculate the startng
to Ans: Program Logic for Pass 2 Ques 20) Describe the advanced method for external symbol.
address for the next control section (CSADDR Pass 2 of linking loader
==
perform the actual loading, Ans: Advanced Method for External Symbols
CSAADR+CSLTH)D relocation, and linking. It uses
modification record and One can improve the efficiency of the linking loader. Also observe that, even though he/she has defined Refer record (R), hefshe
lookup the symbol in ESTAB to obtain its address, hus not made use of it. The efficiency can be improved by the use of local searching instead of multiple searches of ESTAB for
At the end of Pass 1, ESTAB
contains all exiermal uses end record of a main Finally it
defined in the set of control sections together
symbols which is a
program to obtain transter address, the same symbol. For implementing this
one a to external
assigns reference number each in the Refer
symbol record
address
with the starting
address needed for the
execution
of the 1) One can assign a reference number to each external symbol referred to in a control section.
assigned to each. Many loaders include as an program. The pass 2 process Text record and 2) This reference number is used in Modiication
option the ability to print a load map that shows these record of the object programs: Modif+cation records.
symbols and ther adáresses. This information is useful in 1) CSADDR is used in the same For example:
way as it was in Pass I i) Control section name with reference
program debugging -
It always contains the actual
starting address of the number 01.
control section m The other external reference symbols are assigned numbers as part of the Refer record for the control section
Algorithm for Pass 1 of Linking Loader currently being loaded.
The main advantage of this reference-number mechanism is that it avoids multiple searches of ESTAB for the
same
2) As each Text record is read, the object 3)
The aigorithm for Pass 1 of Linking Loaderis given below: the code is moved symbol duning the loading of a control section:
to
specified address plus the
current value or that uses it.
CSADDR An external reference symbol can be looked up in ESTAB once for each control section
begin (specified address +CSADDR) into an array of these values.
3) When Modification record is
1) The value for code modif+cation can then be obtained by simply indexing
getPROGADDR from operating system a
encountered, the
setCSADDR 1o PROGADDR (for first control section) symbol whose value is to be used for modification shown below, with above modification to Refer record:
programs for PROGA, PROGB and PROGC
Ihe are
15
looked-up in ESTAB This value is then added object
while not end of input do Each iteration processes one
1o subiracted from the indicated location in
or
control section
memor
Advanced
Methodfor External Symbols (PROGA)
begin H,PROGA o00000,000063
HPROGA 000000,000063
read next e last step of Pas 2 is to transfer control to the loaded D.LISTA 000040,ENDA 000054
input record [Header record for control D,LISTA 000040,ENDA 000054 LISTC 0ENDC
program to begin execution: LISTB 01 ENDB
sccton 1)The End record for each control section may
RLISTB ENDB LISTCENDC
T000020,0A,03201D,7710o004,050014
et CSLTH 10 control section Jength contain ne T,000020,0A,03201D,77100004,050014
Header record address of the first instruction in that control section tO DE 00054,0F,000014,FFFÉF6,00003F,000014,FFFFCO
T.000054,0F.000014,PPEFF6,00003 E00014,FFETCO
scarch ESTAB for control section name executed.
M O 7 4 ns +m
if found then 2) Two scenarios could be ****M
-MDAMIA DS. +JISTD. ---...
set error flag
encountered
( duplicate external symbol) nore than one control section specifies a M MSAL06.+JJSOJE
M Mo57 0 +FNDC
M 000057 06 +05
eise renster address, the loader arbitrarily uses the M 0ms7 h
-
last one encountered M 0057.06.LISTC...-- M MnSA 06 +05
enter control section name inio ESTAB with 11) M (KSA +TND M 0 S A 06-01
valur CSADDR n0 control section contains a transt M 0 S A 06 -I1STC AM 0O0mKA +n
while record type E do ddress, the loader uses the beginning of the
begin inked program G.e., PROGADDR) as the M.000054. 06.+PROi...
M OSTD -1IND
read next input secord transfer point. M00OSN ISTU. -rnon
if record type = D' then /Define 3) M XYWA n +1IST1
record
Normally,
End
a transfer address
would be placed 1n M N VDcA.
record for a main
for cach symbol in the record do program, but not 10
subroutine igure 4,15
C-64
B.Tech. Fith Semester 7P ed Series (SYstem Softwa (Module 4)
KU Linker
and
Loder
C-65
Advanced
Method for External Symbols PROGB) PROGC Loader Design Options
Reference No.Smbol Address
HPROGB o 007E HPROGB 0m,mTE
There are some common alternatives for organising the
D.LISTB 00000,ENDB 000070
D.LISTBo,END8 LISIA 0A0 loading functions, including relocation and linking. sS
USTAENDA LISTT ENDC LSTA ENDA LSTC ENDC
ENDA 4054 1) Linking Loaders: It Perform all linking and
LISTB 40C3 relocation at load time. The Other Alternatives are
T.O0036,08.031000, 77AL7, OS1000 T.0 05,031Qm, 72027,0STOY ENDB 40D3 Linkage editors, which perform linking prior to load
time
MO7.05, Discuss the machine independent features of
2) Dynamic Línking: In this linking functon 1s
M03E05-ENDA
Juader. Also list the
loader
design options. performed at execution time
Or
MO0E-LSTA
M000070,06,-ENDA
Ma070,06STA
o,0- M000070,06,E
Write notes
on machine independent loader features.
(2017 [04]) Ques 22) Write a note on linkage editors.
Or Or
M00070.05.-STC M.0070,06,-
Write notes on the dillerent loader design options. What is linkage edítor? Compare it wiíth linkíng
MOOU73.06,-END M00073, 0- loader.
-STC 0O0073,06- (2017 [04]D Or
MO007,05-ENDC M000076,06,- Or
M0000760-LISTC List and explain the different machine independent Differentiate between linking loaders and linkage
editors. (2017, 2019 [03])
M0 0-STA M000076,0- lcatures of loaders. (2018[03])
M00007906-ENDA O0S,06,-3 Or
Ans: Linkage Editors
Write short notes on the followinng:
It prior the
M0000C06-FROGS ) Automatic Library Search performs linking to
load time.
editors are found in many computing systems instead of
The linkage
M.mnc.aSTA ) Loader Options
E Or linking loader and the concept of dynamic linking loads
Figure 416 List and explain the diferent machine independent Subprograms at the time of first call. A linkage editor
Advanced Method for External Symbols (PROGC) loader features. (2019[04]) performs linking and relocation, and the linked program is
written on a file or library instead of loading 1t
Or
HPROGC 00000,ao00e5 immediately into the memory,
H_PROGC00000,O0S1 Explain the concept of automatic library search.
DLISTC It produces a linked version of the program which 1is
DLISTC 000030,ENDC0002 2020[03])
tA DASTBENDE O3ENDA 0suSTB SENDB
Ans: Machine Independent Loader Features
written onto a
file or library for execution. When the user
T.0oTs.ac.sioo0007I00004,05i00000 T000015,OC03100000 77 100004,05100000 Some loader features are not directly related to machine
1s ready to run the linked program, a simple relocation
loader is used to load the program into
memory.
0S0,08,0l0000
T000020F.000030,03000s,000011,000000. zchitecture and design. Automatic Library Search and Loader
Options are such Machine-independent Loader Features. In contrast, a linking loader performs all the linking and
MOO M00019,05,-
) Automatic Library Search: This feature allows a relocation operations, including automatic library search,
if specified and loads the linked program directly into the
EDS-LIST programmer to use standard subroutines without
M00001D0s,- memory for execution. The figure 4.18 illustrates the
MOOCLO5-ENDA
M0021,05,- explicitly including them in the program to be loaded.
Ine are automatically retrieved from a
processing of linking loader and linkage editor:
routines
as they are needed during linking. This allows
library
M. -ENDA
M,000042,06,- Object Progrum Object Program
programmer to use subroutines from one or more
MM -STA
M,0042,06,- libranes. The subroutines called
by the program being
M OGc
M,O00042,06,- 1oaded are automatically fetched from the library,
M00048,0LST M00008,56,- linked with the main
M,00304,6,ENDA program and loaded. The loader
M003048 ),-LSTA M,00048,06,- Starches the library or libraries specified for routines
M048,06- that contain the definitions
UOoOE ,-ENDE
M,AB0- of these symbols in the main Lunkc
program. Automatic library search allows programmer
0OUORE LISTE MJAB 6,- O Use subroutines
from one or more libraries.
Memory Program
M.0AE,- (a)
M,000E-LSTA Loader Options:
MOOAE Many loaders have a special
Relocatng
command Janguage that is used to specity options. Lader
Figure 4.17 at s here is a separate input file to the loader
th contains
such control
Symbol and Addresses in PROGA. PROGE and PROGc statements.SomeumS
are asshown below. Thesc are the entnies of ESTAB. The ENDB 40D3 t Same statements can also be embedded in the Menty
main advantage of reference r y input stream between object programs.
number mechanism is that it LSTC 4112 ader
options allow the
avoids muliple searches of ESTAB for the same symbol END 4124 user to specity opuons tn Figure 4.18: Processing of an Object Progran using
dlly the standard processing. The options may De (a) L.kIng Loader andt (o) Lnkage E d r
duning the loading of a controlsection PROGB pecified in three different
Kdarence No.Sy mbal Adaf ways, They are
PROGA PROGB Specified using a command language,
If a program is exeeuted many times wthout being re
Rederence Na SvmbalAddre U63 assembled, the use of a linkage editor substantialy reduce
PROGA LISTA 4040 pecilied as a part of job control language that is the overhead. Resolurion of extemal references and hbrary
LISTE C3 FNDA 4054 processed by the operating system, and searching are pertormed only once. n contrast, a finking
ISTO 4112 DE
specilied using loader control statements in ches library and resolves external reterence
(Module 4) C-67
C-66
B.Tech. Fifth Semester TP Solved Series (System Loader
Software) KTU pirand
A19b), OS examines its intemal tables to determine whether or not the routine is already loaded. If necessary,
every time the program is executed. The linked Dynamic Linking Advantage
program p g i s loaded from the specified user or system libraries. Control is then passed from OS to the routine being called
produced by the linkage editor is generally in form 1) The subroutines that diagnose errorS may nev
IS
a
that to be called at all. However, without using dynami
nced roUu 19(c). When the called subroutine completes it processing, it retuns to its caller i.e., OS). OS then returns
Suitable tor processing by a Relocating Loader. All
extermal linking, these subroutines must be loaded and inked t h e program that ISSued the request (igure 4.19d))
references are resolved and relocation is indicated
by certain mechanism such as Modification Records or cvery time the program
is run.
Bit Mask. Even a ine is still in memory, a second call to it may not require another load operation. Control may simply be passed
though all the linking
has been
performed, 2) Using dynamic linking can save both space for storine
the infomation concerning external
references is often the dynamic loader
to the called routine (Figure 4.19(e)).
the object program on disk and in memory, and time
retained in the linked
program. Therefore subsequent re for loading the bigger object program
linking of the program is done to replace the control
3) Dynamic linking is often used to allow se
section and modily extermal references.
executing programs to share one copy of a subroutine Dynamic Loader
(Part of the Dynamic
Comparison of Linking Loader and Linkage Editor or library, ex. run-time support routines for a high Loader
Operating System)
Linking Loader
level language like C. For example, a single copy of Load-and-call
The linking loader
Linkage Editor the standard C library can be loaded into memory ERRHANDL
perfoms The linkage editor produces
all the linking and relocation linked version of the program. Such 4) All C programs currently in execution can be linked
operation includind to this one copy, instead of linking a
separate co User User Library
nciudinga linked version is,also called as
automatic library search. into cach object program. Progrum Program
then loads the
ItLoad Module or Executable Image
program This load module is generally
direculy into the memory orwritten in 5) In an object-oriented system, dynamic linkingis often ERRHANDL
file or library for later used for references to software
Cxecution.
execution object.
need for The 6) This allows the implementation of the object and its
There 1s no relocating loader loads the
method to be determined at run time.
relocating loader. load module into the memory
The linkng loader searches the If the program iS executed many (a)
The implementation can be (D)
ibrunes and resolves the ümes without being re-assembled
7)
without
changed at any time,
the program that
Issue a load-and- Load the called subroutine
every D choice
extemal relerences every ume then inkage editor is the best afiecting makes use of the call request into memory
ne program is executed. object
The loading requires two The loading is accomplished in
passes Onepass. Ques 24) Define the implementation of dynamic
linking.
Ques 23) Ilustrate the process of dynamic linking.
(2020[06]) Ans: Dynamic Linking Implementation Dynamic Dynamic Dynamic
Loader Loader Loader
Or A subroutine that is to be dynamically loaded must be called
Discuss the dynamic linking with their advantages. via an operating system service request. Load-and-call
Or
This method can ERRHANDL
also be thought of as a request to a part of
Write short note on Dynamic Linking. (2018[03])
the loader that is
kept in memory during execution of the program. Instead of User User User
executing a JsUB instruction to an extermal symbol, the Program Program Program
Ans: Dynamic Linking
program makes a load-and-call service request to the O ERRHANDL
In this thee linking function is performed at executuon time. ERRHANDL ERRHANDL
The parameter of this request is the
Dynamic linking allows a module to include only the symbolic name ofthe
routine to be called. The OS examines its
information the system needs at load üme or runtime. intemal tables to
Dynamic linking differs from static linking, in which the determine whether the subroutine is already loaded.
linker copies a library function's code into each module needed, the subroutine is loaded from the library. Then (d)
that calls it, which is not done in the case of dynamically control is passed from the OS to the
linked modules. If the program is completely linked before
subroutinebeing called. Control is Control returmed to The called subroutine is
When the called subroutine
execution, the subroutines need to be loaded and linked retums to its
completes its
caller (operating system). The
processing t passed loader already loaded
every time the program is run. Dynamic linking provides control to the program that
OS then retums Figure 4.19
the ability to load the routines only when they are in need.
issues the requestL Affer the
Subroutine is completed, the memory that was allocated to
If subroutines are large or have any extemal references,
may be released.
saving in memory space and time is achieved.
However, often this is not done immediately. If tne
Dynamic inking offers the ability to load the routines only Subroutine 1s retained in memory, it can be used by latc
when (and i) they are required. The actual loading and calls the same subroutine without
to
linking can be accomplished using operating system loading tne
subroutine multiple times. Control can simply pas fro
service request. the dynamic loader to the called routine directly. Figure
1) Linkage editors perform linking before the program is 4.19 llustrates a method in which routines that re to De
loaded for execution.
dynamically loaded must be called via
an OS ser
these operations at load
2) Linking loaders perform same request. Instead of executing a JSUB instruction refemn
time. o an external
symbol, the program makes a load- -call
3) Dynamic linking postpones the linking function until servicerequest to OS. The parameter of this request Is the
execution time.-A subroutine is loaded and linked to DOlC name of the routine to be called (gure
the rest of the program when it is first called 4.19(a).
Module 5
Module nnauna Code
hefollowing
MACRO
lmacro header
Flow of Control during Expansion
The default. flow
sequential.. Thus,
during
of control
in the absence
macro
of
expansion 1s
preprocessor
a macro are visited se-
satement IImacro prototype statements, the model statements of
SUM &x, &y the macro
quentially starting with the statement following
Macro Processors gtutenment /model statement prototype statement and ending with
preceding the MEND statement.
the statement
LOAD II model statement
ADD /model statement statement can alter the flow of control
MACRO PROCESSORS influenced by the form of
the programming lanou STORE&x
pre-processor
during expansion such that some model
statements are
statements, The meaning oese statements and End of defintion unit
translation into their MEND
either never visited during expansion, or are repeatedly
Ques 1) What is macro machine languages are of no Concem
by expanding macros?
processor? What do you mean during the macro expansion. header statement indicates the existence of a Visited during expansion. The former results in conditional
The macro 1ne next statement in the defintion
and the latter in expansion time loops. The flow
definition unit. expansion
Ans: Macro Processor The design of a macro processor 1s nacro
for a macro call. it consists of the name of control during macro expansion is implemented usinga
usually machine nit the prototype Macro Expansion Counter (MEC).
A macro
processor is a
program that copies a stream of
independent. Macro processors
are commonly Used in
is
the list of parameters. In the above
f the macto and macro is SUM and the
text from one assemblers, high-level programming languages, and of the list of formal
place to another, making a systematic set of operating system command languages. example name
Algorithm: Macro Expansion
replacements as it does so. Macro are &x and dCY. the prototype id follwed by the
embedded in other programs, processors are often urameters
statements. These are assembly statements After the calling stage macro is
next expansion the stage.
Expanded source o calledmodel
compilers. Sometimes they are such
as
assemblers and ource the
Macro STRG MACRO
the macro call as a result of macro expansion The assembly statements (model statements) replace
STA DATAI||(Macro Expansion)
standalone programs that shich replace
can be used to Header macro call as a result of macro expansion. The flow of
process any kind of textL
Macro
TB
DATA2|| What is macro invocation?
control during macro expansion is implemented using a
Expanding the Macros Ques 4) Macro Expansion Counter (MEC).
Deliniio STX DATA3
A macro is a unit of STA DATAIS
specifications for program generation MEND STB DATA2
Ans: Macro Invocation
The algorithm is shown below:
through expansion. Macros are special code acro STX DATA3 the macro the nest stage 1s to call the
are delined once in the
fragments that call STRG
After defining
1(Macro Expansion Counter (MEC)= statement number
program and are used repetitively invocation statement gives the name of the
macro. Macro
by calling them from various places within the STA DATAI
macro instruction being invoked and the actual parameters of first statement following the prototype statement,
is similar to the program. It STRG STB DATA2
used to
subprogram in the sense that both can be STX DATA3 o be used in expanding the macro. invocation
The macro 2) While statement pointed by MEC is not a MEND
organize
the
program better by
frequently used fragment into a different block.
the
separating-Out statement is often referred to as a macro call. In the above statement
its macro name along With
Ques 3) Explain the macro definition.
example, the macro is called by 1 If amodel statement then
2020[02) actual parameters. a) Expand the statement
The main program calls this block of code as Actual parameters
and when Or SUM MN b) MEC=MEC + 1;
needed. Both of them can have an
associated list of Write the syntax of macro definition and define MEND lmacio call
ii) Elsei.e., a preprocessor statement)
parametcrs, A macro
represents a commonly used group of directive.
statements in the source MEC: = new value specified in the statement;
macro processor
programming language. The Or Ques 5) Define macro expansion. Write its algorithm.
replaces each macro instruction with the Explain the concept of macro definition with the lhelp Or 3) Exit from macro expansion.
corresponding group of source language statements. This of examples. What is macro expansion? Discuss the flow of control
is called 2017 2.5)
expanding the
macros Or during expansion. MEC is set to point at the statement following thee
Ilustrate macro definition using an prototype statement. It is incremented by1 after expanding
Ques 2) Write the basic macro
processor function.
example. (201903 Dr
with the help of model statement. Execution of a preprocessor statement
Ans: Macro Definition
Aplan the concept of expansion
(2017 [2.51) can set MEC to a new value to implement conditiona
Ans: Basic Macro Processor Functions A macro definition
Examples.
consists of Or expansion or expansion time loops.
A macro
represents a
commonly used group of statements 1) Macro prototype statement.three parts:
in the source Explain the macro expansion. (2020[02])
programming language. 2) One or more model is the of lexical substitution?
statements, Or Ques 6) What use
3) Macro preprocessor
The macro processors do macro statements. Ustrate macro definition and expansion using an Ans: Use of Lexical Substitution
cach macro instruction with the expansion by replacing Note: Each
Example. (2019[01)) Lexical substitution is used to generate an assembly
corresponding group of parameter in macro defintion begins Wiu A model statement
source language statements, Macro
instructions character Ans: Macro Expansion statement from a model statement.
programmer to write a shorthand vers1on ol a
allow the &(ampersand), this facilitates substituuo Consists of 3 types of strings:
program, parameters douring macro Uhe calling stage macro expansion is the next stag
and leave the mechanical details to be handled by the expansion 5SCmbly statements (model statements) replace hne 1 A n ordinary string, which stands
for itself.
macro processor A macro is defined using the 2) The name of a formal parameter which is preceded by
follwing syntax Ocall as a result of macro expansion. The macro the character &
MACRO CApansion for the above
example is given a
For example, use a macro SAVEREGS to save the LOAD 3) The name of a preprocessor variable, which is also
contents of all Name> Iparameter List) M
registers onSICIXE machine, instead of a ADD N
preceded by the character '&
sequence of seven instructions (STA, STB, etc.),.
STORE During lexical expansion, strings of type I are retained
Kassembly language code> without substitution. Strings types 2 and
of 3 are replaced
The functions of a macro processor involve the Two k
substitution of one group of characters or lines for another. olions concerning macro expansion are as follows by the 'values of the formal parameters or preprocessor
"pansion Time Control Flow: This determines the parameter is the
The design and capabilities ol a
processor may be macro variables. The value ot a
tormal
MEND n which model statements are visiled during
acro expansion, corresponding nctual parameter string
&EEEEEEEE 3338EEEE5888daasuststeuea ******

91t

Macro Invocation ----- *********** Maer


Macro Dcfinition *****-----
)KTU
Figure 5.3 shows the Specified device into register A, taking
macro expansion.
generation of unique labels within a Consider the example of a
Macro detining anothe Macrn r from a
haractenecessary test-and-wait loop. It is convenient to
In the example below, the body of the first M 1. SP=-1
25 RDBUFF MACRO r of ike RDCHAR in the definition of RDBUFF 2. Call RDBUFF BUFFER, LENGTH
30
&INDEV, &BUFADR, &RECLTH (MACROS) contains statement that define RDRI
CLEAR e rogrammer who is defining RDBUFF need not
WRBUFF and other macro instructions for SIC machi
CLEAR that details of device access and control. SP=
S
CLEAR The body of the second Macro (MACKOX) definesth ory about
the
S)|
Macros
+LDT #4096 same macros for SICNE Machine. A proper invocatio cxpanded
0 SLOOP TD of using RDCHAR in this way would be S 10+1+1+1+1+1 CLEAR
=X&INDEV would make the same program to perform ndvantages
JEQ he
The more complex machine, where the code S6) CLEAR A
0
RD SLOOP invocation to run on either SIC or SICNE machine. on a
greatersingle S4) BUFFER
COMPR =X'INDEV even character mgnt be longer and more
CLEAR s
IE SEX
MACROS for SIC Machine (Unplicated,
LENGTH +LDT H4096
&BUFADR. X
S(6) FI
SO 1 MACROS MACRO (Delines Sie standard version macros)
1INR T nansion of RDCHAR would also proceed normally.
JLT RDBUFF MACRO &INDEV,CBUFADR,&RECLTH
SLOOP
of this expansion, nowever, a problem would
3 SP=7 TD X F
90 SEXIT
STX &RECLTH (SIC standard version)
Ar the end S)_
5 MEND ppear
LS(2) JEQ-3
(a) RDBUF Macro Definition
MEND (End of RDBUFF) the definition of RDCHAR
S 6) RD=X F1'
the end of wa N= SP -S (SP)
RDBUFFl WRBUFF MACRO &OUTDEV, &BUFADR,&RECLTH
When
EXPANDING would be set to FALSE. If S) BUFFER
BUFER. Length ncognized, a
S6) LENGTH
-2
CLEAR NX (SIC standard version} grOgramming language
at
supPports recursion is not S(6) F
=7-1-2
CLEAR aYailable, the programmer must take care of handling such =4
CLEAR S_ MEND End of WRBUFF) SP =S (SP) = 1
addresses and values of local variables.
+LDT# 4096 ienms as return S(8) 50+1+1+1+1
SAALOOP TD=XF S (9)
AALOOP
An example is shown in figure 5.5: SC0)
MEND (End of MACROS)
COMPR A.S 0 DEFTAB
JEQ SEXIT Figure 5.4 ()
10 RDBUFF &BUFADR, &RECLTH,|
STCH&BUFFER. X RDBUFF &INDEV SP=1 COMPR A, S
TEXR T MACROS for SIC/XE Machine CLEAR X
SD STCH
JLTS AALOOP RDCHAR CLEAR A S(2) 15+1+1t1+1+1+1 BUFFER
I SAAEXIT | STXLENGTH 1 MACROX MACRO (Defines SIC/XE macros] 30
CLEAR S
S (6)| TDAR
(b) Resulting Macro Expansion 2 RDBUFF MACRO +LDT #4096
&INDEV,&BUFADR,&RECLTH S4 BUFFER JLT
SLOOP
Figure 5.3: S(5) LENGTH
(SIC/XE version) SLOOP RDCHAR ?3 S (o)L FL SEXIT STX
Labels used within the macro LENGTH
body begin with the special COMPR A, S
character Sin Figure 1(a). In Figure 1(b), each MEND (End of RDBUFF) JEQ SEXITT N=1+1-2
symbol
beginning with S has been modified by replacing S with WRBUFF MACRO &OUTDEV,&BUFADR,&RECLTH STCH 21, X =0
SAA. TIXR T SP=S (SP) =S (1)=I
(SIC/XE version) JLT SLOOP Figure 5.6: Recursive Macro Expansion for the Example
Ques 9) Define the two approaches for macro0 SEXITSTX 2 in Figure 5.5
MEND (End of WRBUFF} MEND
processor design.
0 Ques 11) Discuss the one pass maero processor. Also
Ans: Approaches for Macro Processor Design RDCHARMACRO &N write its algorithm and data structure used for this.
MEND End of MACROX) TD = X 21
Approach I: It is easy to design a two-pass macro Or
which all macro definitions Figure 5.4 (b) JEQ 3
processor in are
processedd Write the one pass macro processor algorithm.
during the first pass, and all macro invocation statements RD =x *?1
A MEND
2020[071)
are
expanded dunng program that is to be run on SIC
the second passs.
MACROS whereas a program to be run
system could invoke Or
Figure 5.5
However, such a two-pass macro processor would not invoke MACROX. However, on SICXE can Write and explain the algorithm for One Pass
allow the body of one macro MACROX does not define defining MACROS or Macroprocessor. Briefly discuss various Data
instruction to contain RDBUFF and WRBUFt
definitions of other macros (because all macros would These definitions are structures for a design of One Pass Macroprocessor.
processed Froblem Associated with Recursive Macro Expansion
MACROS or MACROX is only
of
when an invocauon Or
have to be defined during the first pass before Tevious Macro
invocations were expanded).
any macro expanded. Design Does not take care of recursiye
macro expansion.
Describe the data structures used in a one pas macro
Ques 10) How could processor algorithm. (2017 [03)
a recursive macro proceor De
Approach 2: A one-pass macro processor that can implemented? Or
alternate between macro definition and macro expansion is
Solutions Give the algorithm for a one pass macro processor
Or )Write the macro processor in a programming
able to handle macros like those in figure 5.4. However, Explain recursive macro expansion with (2017 [07])
one-pass may be enough because all macros would have to example. (2017 (05)
anguage which automatically takes care of the Or
be defined dunng the first TCCursive calls thus retaining the local variables, working of one pass Macro Processor.
pass belore any macroo Or Explaint
invocations were expanded. What do you mean
by recursive (2018[071)
What are the expanso macro Iwritten Or
possible problems associated with in a
langunge without recursion Suppo
The definition of a macro must appear before any
Ans: Recursive it? 09 0 take care of pushing and popping the local What are the data structures required for a
Macro Processor
statements that invoke that macro. Morcover, the body of
contain definitions of the other There can be a
condition that invocation Implementation ADIes
values,
and return addresses thus retaining their microprocessor algorithm'? Explain the format of each.
one macro can
macro done by another. The purpose of of one macro (2019104))
RDCHAR is to read o Or
99:09

- Address decreases
B.Tech, Fifth Semester TP Solved Series (System Softwn (Module 5) C-77
ware) KTU Processors
Ques 12) Discuss different Macro
macro with example. types of
parameters used in Example: the macro definition usin of Macro Parameters: Most macro
keyword Concatenation WHILE-ENDW Structure
paurneters to be concatenated with
D
Or
parameters processor
allows
i) When an WHILE statement is encountered dunng
Writenotes on MACRO ther character strings. For example, consider that
the expansion of a macro, the specified Boolean
suitable examples. keyword macro
parameters, giving INCR_M &MEM VAL=, the parameter to such a macro instruction is named Cxpression is evaluated.
(2017 [05]) &INCR_VAL=, &REG= &ID. The body of the macro definition might contain
Or i) TRUE
Differentiate between MOVER &REG, &MEM_VAL a statement like
parameters.
Keyword and Positional macro ADD &REG, &INCR_VAL LDA X&ID1 a) The macro processor continues to process
lines from DEFTAB until it encounters the
(2018[03]) MOVEM &REG, &MEM_ VAL &ID is concatenated alter the string "X and before
next ENDW statement.
Ans: Types of Parameters in MEND
Macro the string T . b) When ENDW is encountered, the macro
1) Positional Parameter: Consider the following macro calls LDA XAL (&ID = A)
The parameter from macro processor returns to the preceding WHILE,
prototype and arguments from the macro call are INCR M MEMVAL =
A,
INCR_VAL =B LDA XBI (&ID =B) re-evaluates the Boolean expression, and
associated with each other REG = AREG & is the starting character of the macro instruction;
according to their
positions. A positional parameter is written as but the end of the parameter is not marked. So in the
takes action based on the new value,
ii) FALSE: The macro processor skips ahead in
Sparameter name>, For
where SAMPLE is the nameexample,
&SAMPLE, INCR M
MEM_VEL = A
INCR_VAL =
B,
REG =AREG case of &lDi, the macro processor could deduce the
meaning hat was intended.
DEFTAB until it finds the next ENDW statement
of a parameter. The and then resumes normal macro expansion.
value of positional formal parameter XYZ 15
a are now equivalent.
of is not
determined by the rule of
positional association as Dilference between P'ositional and
2) Generation Unique Labels: It to
use labels for the instructions in the macro definition,
possible 4) Keyword Macro Parameters: The types of macro
follows: Keyvord Parameters parameter are classified as:
i) Find the ordinal position of XYZ in the list of 1) In positional parameters here S one to one since every expansion ol macro would include the
i) Positional Parameter: Parameters and
comespondence between macro definition and macro call label repeatedly whieh is not allowed by the
fomal parameters n are associated according to their
the macro prototype The calling sequence should be same as assembler. This in tum forces us to use relative arguments
statement. defined sequence positions in the macro prototype and invocatiol.
2) In keyword parameters
addressing in the jump instructions. Instead we can If an argument is to be omited, a null argument
11) Find the actual parameter specification occupying sequence is not important and use the technique of generating unique labels for (two consecutive commas) should be used to
the ordinal number of parameters used while
same
position in the list of actual
are also not important
calling the macro every macro invocation and expansion. During macro maintain the proper order in macro invocation:
parameters in the macro call statement.
expansion cach S will be replaced with SXX, where For example, RDBUFF OE, BUFFER,
Example: consider the call XX is a two-character alphanumeric counter of the
Ques 13) Define the machine independent features of LENGTH, , 80
NCR A, B, AREG number of macro instructions expansion.
macro processor. It is not suitable if a macro has a large number of
In the following macro definition: Or 3) Conditional Macro Expansion: If the macro is parameters, and only a few of these are given
MACRO List the machine independent expanded depends upon some conditions in macro values in a typical invocation.
INCR
macro processor
features. Also discuss ditferent types
&MEM_VAL, &INCR_VAL of parameters definition (depending on the arguments supplied in i) Keyword Parameter: Each argument value 1s
&REG used in macro with example. the macro expansion) then it is called as conditional written with a keyword that names the
MOVIVER &REG, &MEM_ VAL Or macro expansion. Macro def+nition is designed in
corresponding parameter. Arguments may appear
ADD &REG, &INCR_VAL Explain the following: such a vay that it generates different instruction in any order. Null arguments no longer need to be
MOVEM &REG, &MEM_ VAL 1) Conditional expansion
macro
sequences when different relations hold between the used.
MEND 2) Generation of unique labels actual parameters of a call. For example, GENER TYPE=DIRECT,
Or
CHANNEL=3
Following the rule of positional association, values of the Explain conditional macro expansion with an example. Macro-Time Variables It is easier to read and much lesS error-prone than
formal parameters are (2017 (05)) Macro-time variables (often called as SET Symbo)
the positional method.
Formal Parameter VluC Or can be used to store working values during the macro
Is it possible to include labels in the with symbol &
MEM VAL body of macro expansion. Any symbol that begins
Ques 14) Differentiate between a Macro and a
definition? Justify your answer. (2018[06) and not a macro instruction parameter is considered as
INCR VAL B Subroutine. (2019[03])
Or macro-time variable. All such variables are initialised
REG AREG Write Or
short note
parameters within a character string.
on
concatenation of macro to zero.
What is the difference between macro invocation and
2) Keyword Parameter: For keyword parameters,
(2018[04)) subroutine call? (2020[03))
Or If the value of this expression TRUE:
<parameter name> 1s an ordinary stnng and
Explain the different types of conditional )The macro processor continues to process lines
parameter kind> is the string= The <actual macro Ans: Difference between Macro and
Subroutine
expansion statements and their from the DEFTAB until it encounters the ELSE
parameter spec> is wntten as implementation Table 2 shows the difference between Macro and
Subroutine:
examples. (2018110) or ENDIF statement.
formal parameter name> = <ordinary
tring> Write
Or ) I f an ELSE is found, macro processor skips lines
Table2: Diference between Macro and Subroutine
notes on conditional macro in DEFTAB until the next ENDIF Procedure
expansion. (201910 3) Once it reaches ENDIF, it resumes expanding thhe
Macros m/c Corresponding
The value of the formal parameter XYZ is determined
Or
The corresponding The
Explain the following machine independent mac macro in the usual way. machine code is watten code is wnitten only once
by the rule of keyword association as follows: processor Ieatures: (2020[10) every lime a
maero is in memory
i) Find the actual parameter specification which has 1) Generation of unique labels.
the form XYZ= <ordinary stning>.
If the value of the
expression is FALSIE calledin a program.
2) Keyword macro ahead in DEFTAB
more Program lukes up
ii) Let <ordinary string> in the specification be the parameters ne macro processor skips
ELSE or ENDIF grn
takes up
comparatively less
next memory' space,
string ABC. Then the value of the formal Ans: Machine Independent Macro Processor Feature Cncounters
memory space.
The design of
macro processor doesn't statement
parameteris ABC.
architecture of
depend on
the machine. Some ne macro processor then
resumes normal macro No transter of programransterring of program
extended features " counter is required,
macro processor are; expansion, Lcounter
CW
( o d u l e 5)
C-78 B.Tech, Fifth
Semesterisoed
des(ystem Softwa ProcessIs
KTU ATo
Some of the data structures required DY a
ose Macro Processors: 1ne most 2) D
can
processo and he language ranslator
Ques 15) DIscuss the
as an aid to
eral-i
various design options for macro of macroprocessos
1S
processod and
Tuncuons
can
language progra mg Oren Such combined, Many utility subrouines
ASaCro Frocessors Design Options with, or closely related be used by both the language tránslarOr and n
nother. The D
1s sSrocessors are combined nning
pansion: There can be a condition that invocation A, taking care onOy
of one maCTtO
also
Deen avC
processor, These incude sucn op
EDCu or the necessary t e s t - n S he asscmbler. MncroprocSSOS onverting numennc
program1
A D h e definition of RDBUFF SO
1oop. It is convenient to use tnat uiC
eveloped
ngn-levei
for
sonme
input 1o internal representauon
POgrammer who i values irom extema
D g KDBUFF need not wory about the details of device access and contro. anguages
An
example is shown in figure 5.9: Processor W anguage TranslatorsS Disadvantages Macro Processor within Language
facro
macro procesSOD I g PP
0
DEFIAD
The and
TranslatoS. wntten to work
RDBUFF &BUFADR, &RECLTH, That is, they proc exDanded version of ney
must
De specially designed and or
RDBUFF NDE macro invo . TThis expanded program is then
with
a particujar implementation
of an assembler
compiler (not just with a particular prograng
CLEAR he sour assembler or compiler. In this case
RDCHAR A
o an
Ised as up
with the language).
CLEAR SS
macro processing runcuons are combinedmethod must
+LDI =Uo translator itsell. Ihe sSimplest 2) The costs o macro processor development
uage
line-by-line
SLOOP RDCHAR 25 chieving this
sort
or combinatlion
is a
approach,
niS the
therefore be addcdO
translator, which results in a more expensive preee o
sng
COMPR A macro processor Stalemens ana
JEQ SEAI orocessor
reads tn
SOurc PrOgrm t
SOLwa
21,A erforms all o translator as they are
JLT SLOOP ines are pass ime instead of being wrilen t DEVICEDRIVERS
SEXIT *MEND enerateu source file. Thus, the macro processor
Ques 17) What is device driver? Del+ne
the anatomy
rates as a sort of input routine for the assembier or of device driver,
RDCHAR MACRO &INN compiler. Or
TD=A What are the major design
JEQ -3
Ques 16) List the advantages and disadvantages of What is Device Driver?
a
Devce 2018105)
macro procesSor and macro prOcessor 155ues OL a
Diver
general purpose
translators,
wwith in language ot a device driver with the of
Explain the anatomy help
FigureS. Macro Processors diagrams. (2019[05))
Ans: Advantages General-Purpose
Ans;
SP=-1 AdvanB does not need to learn
2Call RDBUFF BUFFER, LENGTH, FL ntma
macro facility for each compiler or Ans: Device Driver
A device driver is a program routine that links a peripheral
embler language, so much of the time and expense
a 1t SS
S0)_ involved in training are eliminateca. device to an operaing system or compurer.
10-1+141+141 Macros expanded essentially a sottware program nat ows
CLEAR X The costs involved in
producing ageneral-purp5 employ a device, Suci Ise It is
as
(4) BUFFER CLEAR A cro processor are somewhat greater than those ror nrohend the detailed
LENGIH CLEAR S developing a language-specitic processor. owevc Wnte P . douice's command
(6)
language a d
HLDT #4096 nis expense does not need to be repeatea lor eacn
characteristics and contains the speciic machine language
language; the result 15 a substantal overal Savg " . necessary to perform the functions requested by the
software development cost a new hardware device is added to the
application. when
1TD=X Savings in soltware maintenance eftort should
also be
Computer, such aS a CD-ROM dnve, a printer, or a sound
to run it. The
Card, its driver must be installed in order
FI
Ieilzed,
Over a peri0d or years, tnese maintenanCe "calls" the daver, and the driver "dnves"
cOSts may be even more significant than the original operating system
= S
cost 1or software development, device
=4
Disadvantage General-Purpose Macro Processors The basic inputoutput (Uo) harUwae Teauressuc
P=S (SP)=1 One polential problem with general-purpose maCro ports, buses, and device c o o c
processors
involves the syntax used for macro deliniuon ariety ol 7
aud macro invocation statements, WIth most Specia daices the kernel of an
inique ic n to use device driver modules.
COMPR A, Ss acro
"
proccs5ors,
01D1 10 Satements im ne source programming device drivers present a unitoim deviceicees
STCH
15+1+1+1+1+l+l| BUFFER, age, intertace to the VO subsystem.
(4) BUFPER nlages Macro Processor within Langunge Each of the different types of /O devices is accessect
$IOP ntertace. The
(6)
LENGTH EXIT FrAnslators
avods he
through a Standardhzed
tangible dreronces are encapstutated m
set of tunctions-an
semel moctules
making an extra pas5 Over source
siom
Figure 5.10: Kecurp)VE MiacrO YpalisioD =l+]-2
1or the
LENGJH_ g (riling and hen rendDg ne CNpandcd (i.e., device drivers) that internally are customizcd tor each
FKample in Pigure 5,9 ource file), so it can be more efficlent than using n device, but that export and utilize one ot the standar
nacto preprocessor intertace
C-80
B.Tech. Fifth Semester 7P
Solved Series (System Software) Kn Processos

(Module 5) C-81
Design Issues of a Device Driver Ques 18) Define the various types of devic
Macro
To make the evice drivers between Character and Block Device Driver The task calls the device driver via a kernel device
design of device drivers easier, we have block
Also differentiate character and
divided the issues to be considered into three Or
device driver, iflerence
cter Device Drives Block Device Drivers call. The device entury routine gets blocked on
broad
categories (Design issues of a device
driver): Differentiate between characters and bloek
Chunnut and output Transters data in blocks, semaphore and blocks the task in that way. When an
rather than one byte at a time. input comes from the device, it generates an interrupt
rform
)
Operating system/Driver ata am
2)
3)
communications
Driver/Hardware Communications
Driver Operations
drives.
Or (2017,2020device
05
onecharictCr
Support singie nardware. Support
hardware unit.
more than one and the ISR releases the semaphore and the device
Entry routine returns the data to the task and the task
Distinguish between Character and Block D Do not have file-like
logical name assigned logical continues it execution.
The first
category covers all of the issues related to the Drivers. Device Have names.
exchange of infomation between the device
driver and
Or (2018(05) 1othem
1sually control
terminal or Usually control floppy-disk,
2) Asynchronous Device Driver: When a task calls an
asynchronous device driver it means that the task will
operating system. t also includes Differentiate between Character and Block fixed or magnetic tape daves._
the kermel
provides for the
support functions that Drivers. Device pranter
mples: sOund cards, EXamples:
USB cameras, only check if the device has some data that it can give
The second covers
benefits of the device diver.
those issues related to the
exchange or
Ans: Types of Device Drivers (2019[04) Example
nallel cards, serial ports hard disk. D+sk-on-key to the task (igure 5.13). In this Cxample the task is
just checking if there is a message in the queuc. The
the intormation
between the device driver and the device it Depending upon how data is fetched by the of a device driver.
controls. This also includes issues such as how device drivers can be dividcd into two categories levio Oues
Ques
19) Give the general design device drver can independenty of the task send data
talks to hardware and how software (2017 [05]) into queue.
the hardware talks 1) Character Device Drivers: Character device dnvers Or Device Driver
back. are intended for those ices, which have
The third covers issues a nscribe the general design of a device driver. (2020[051)
keyboard simple
related to the actual internal character basecl interface such Task Driver Entry
as the
operation of the driver itself. This S Or Calling Kermel KOutine
1) includes
Interpreting commands received
devices do not require any buffering as
they send a design and anatomy of. a device Read 0 Dev Read O ]
from the operating receive data in single Eyplain the general
System character chunks. Character driver with
the help of diagrams. (2019[05])
device drivers normally pertom VO
2) Scheduling multiple outstanding requests for in a byte stream.
of Device Drive
servce They can also prOvIde adaiional Ans: Design
Managing the transfer of data across both interfaces interfaces
present in block drivers, such as I/O control (iocnot t Is very good if you can
(operating system and hardware) When you design your system
commands, memory mapping, and the soltware 1nto two parts, one that is hardware
4) Accepting and processing hardware interrupts device polling. split up
Maintaining the integnty of the driver's and the
User Proces Kemel independent and one that is hardware dependent, to make Device
kenel's data structures. iteasier to replace one piece of the hardware without
Driver In the hardware
having to change the whole application. Figure 5.13: Asynchronous device driver
Anatomy of Device Drivers dependent part you should include:
Device driver take on a read/write 1) Initialisation routines for the hardware The task calls the device driver Via a kermel device
special role in Linux kernel. They sy stem call< ad/wnte system cal read/wnte
are "black
boxes that make a particular piece of hardware handler ntry poins 2) Device drivers
call. The device entry routine receives a message from
3) Interrupt drivers the queue and returns the data to the task. When new
respond to a well-defined internal
The driver translates between the programing
interface. data arrives from the device the ISR puts the data in a
hardware commands The device can then be called from the application using message and sends the message to the queue.
understand the 2) Block Device Drivers: Devices that
by device and the stylized
interface used by the kernel. User activities areprograming system are known as block devices.
support a file RTOS standard calls. The RTOS creates during its own
performed for these devices are known as
Drivers writen initalisation talbles that contain function pointers to all the Ques 20) Describe the working of device driver.
by means of a set of standardised calls that are block device drivers. device driver's routines. But as device dri vers are
independent of the specific operations that act on a real Block device drivers are intended
that have a data block based
for those devices initialized after the RTOS has been initialized you can in Ans: Working of Device Driver
hardware is then the role of the device driver.A interface such as the hard your driver use the functionality of the RTOS. When you
device disk. In order to When we get a peripheral device such as printer, scanner,
driver has three sides: improve speed and
devices transfer the whole data buffer eficiency, these
design your system, you also have to specify which type of keyboard or modem, the device comes together with a
1) One talks to the hardware and at one time device driver design you need. Should the device driver be
2) One talk to the user. User Process driver CD which needs to be installed before the device
Kermel interrupt driven, which is most common today, or should starts working.
3) While one side talks to the rest of the kernel.
Driver
the application be polling the device? It depends on the Application Application
Read/write system call device itself, but also on your deadlines in your system. Applications Programl Program 2
User
handler But you also need to specify if your device driver should
Suriegy
buffer management Called synchronously or asynchronously.
Kernel 1) Synchronous Device Driver: When a task calls
Device Diver synchronous device driver it means that the task will
buffer cache until the device has some data that it can give to the
headers Keme
task (igure 5.12). In this example the task is blocked
Hardware buffer cache data Sun Common SCSl Architecure (SCSA)
on a semaphore until the driver hat been able to read
Figure 5.11: Anatomy of Device Drivers any data from the deVICe.
Block device
Device Driver Host bus adapter Eost bus adapter
drivers take a file system
1om ol request, in te Task
driver driver2
A device driver performs the
following jobs: buf(9S)
a
stnucture, and issue the IO operalons Driver Entry
1) To accept request from the device
to the disk to
transfer the specified block. The
main Calling
Read
Kernel Routine
independent interface to the file is the HDevRend OJ}
software above to it
Block device
system
drivers can also provide a
strategy9E) roune Hanfivare Applitation
Togram
Ppncano0
Pogram
2) Interact with the device controller to take and give /Oo character dnv
interface that allows
and perform required error handling. utility programs to bypass he
5ystem and access the device directly. As soon we instull the driver software into the computer, it
3) Making sure that the request is executed
successfully This device scces detects and identifies the peripheral device and we become
s commonly referred to as
device. For
the
interface to a blo
raw ISIR Device able to control the device with the computer A device
example, disks
as block devices
are
commonly implemenic ---
driver is a piece of sottware that allows your computer's
Tigure 5,12: Synchronous device drlver
B.Tcn. as Ques
sociateath the
tasks
C-82 main
1our
Index
Blemen
operating system to communicate with a bardware device
out
D o c u m e n t
List
the
E d i t i n g P r o c e s s .
Q018|021 5 Ans: Salient Aspects of Text Editor
A text cditor has to cover the following
main aspects
the driver is written for. Generally a driver communi progy related to document creation, storage and revision
Ans: Editing a
computer
1sise a target
ogramtha
with the device through the
computer bus which is us allowsa An important
editor
c o mdocumen Interactive User Interface:
interactive
putercnt 1)
connect the device with the computer. Device dnve
works within the kemel layr of the operating sys
Kernel is the part of the operating system that dirteu

An
user
to
i n c l u d e s

c r e a t e
objects

and
suCh
diagramis,

as
ine art,
uter
diagrams
Doeumen
photogra Dh
Figure 5.14(a)
consideration of a document is its layout
to a human
reader. For this it is essential to present a documentin
(terminal)
cquations
tables,
strings
strings are n e
are
pimary ele a rectangular form, on the monitor screen
interacts with the physical structure of the system.
of accessing a device directly, an operating system lods
Inste text
editors,
charicter
ments of Index Element or via a printer (as an output of
be
the interacive
process). Further since a document can potentially
t h e t a r g e t text.
the device drivers and calls the specific
diver software in order to execute specific tasks on tne
functions in a
in
Document-Editing
Proo 05 very large and since in a computer
terminal can
a time,
display only a limited size of a document at
Involved interactiv
codes Steps in a n ve user-computer
device. Each driver contains the device specific process
hence it IS necessáry for a text editor to display only
Document-editing a
required to cary out the actions on the evice tasks
ter
Consider an example of a printer, when it is connected
to

dialogue
)

has four
Select the part
of the target iocument
documen
tO De
Viewed Figure 5.14(6)
portion (page). of a large document that cannot
displayed in entirety at once.
be
and manipulate
view c
the computer and the specific device driver is installed.
device object is created on the computer which is designed 2)
Determine
how to
fomat this
on-line and how to Graphica
Editors: Graphical edítors are GUI
The process of creating and revising a document in a
tne display it. Graphical User Interace) based editors. These are For interactive editing a
to control the device. This device object represents execute
operaions hat modis.
that
modiy the
ch user-friendly.
The Window-based editors are computer is called editing.
pinter and its physical structure modes hat
allow your
3) Specify
and
target for the graphical editors. Notepad is an
text editor displays a document on the terminal and
computers operating system to control its functions.
document. hest example graphical edito
accepts various types of input from the user through
view appropriately. for a
4) Update the example different types of input devices, viZ., keyboard,
P to pint a
When we choose an operation (like Control + text editor. Also def+ne the various mouse, data-tablet (flat, rectangular,
document) on the printer then this command goes
to tne above task invoíves:
Oues 23) Define electromagnetically sensitive panel over which a ball-
The 3
dog
Selection ot the part of the cument to be
editors.
text
device dnver through the kemel of the operating System. of
1) Travelling: edited. It ypes
point-pen-like stylus is moved and the coordinates of
Resultantdly a calling program invokes a routine in the
viewed and involves first travellino Ans: Text E d i t o r s
the stylus is sent to the system). Initially the text
the document to locale tne area of nterest such as tool that allows a user to create and revise
device diver and the diver issues coresponding
next t editor is a
editor may display the starting portion of the
and Tind pattern this task can be carried out
commands to the microcontroliers within the printer.
screenful, "bOtom .
ncuments in a computer. 1hough document. During editing the user may give inputs to
of text editor commonly refers to the
Further these microcontrollers control the components 2) Filtering: The selection of what is to be viewed and modes, the word
the printer like motors etc. to start printing the document does this interactively.
A popular text editor in bring other portions to the display. Besides the
manipulated is controlled by Tillering. Filtering ev lthat displayed page, there is the notion of a point within
or mainirame computers is called XEDIT. In
the relevant subset of the target document at the point of BM's large the page, indicatd by an casily distinguishable
Ques 21) What is a Device Driver Entry Point? the two most commonly used text editors are
next scTeenrul of text or next INIX Systems, called the cursor, where the next insertion.
interest. such as statement and v. n Personal COmputer systems, word symbol
deletion or modification will be effective.
Ans: Device Entry Point
Driverfunction within a device dnver that can 3) Formatting: Formatting
determines how
then Emacs
nrocessors
are more common than text editors. However,
An
entry point is a result of filiering will visible representat
be seen as a of mainframe and UNDX text editors that
be called by an extennal enuty to get access to some dr+ver
(the view) on a display screen or other device. there are variations example is
Many text editors allow pictures and other non-text
for use on personal computers. An
functionality or to operate a device. Each device driver are provided
XEDIT for Windows.
information to be included in a document. Such
provides a standard set of functions as entrT points.In 4) Editing: In the actual editing phase, the arget document KEDIT, which is basically editors provide mechanisms to either create/modify
illumos kernel uses entry points for these general task is created or altered with a set of operations SUch as Such information or embed such objects ins+de the
of Text Editors
areas insert, delete, replace, move or copy. Manuscpt Types creation lines of text are
Line Editors: During original document. The output of an editing process, 1.e., the
1) Loading and unloading the driver oriented editors operate on elements such as single 1)
2) Autoconfiguring the device - Autoconfiguration is the recognised and delimited byend-of-line markers, and document, can be either saved as file(s) in the
characters, words, lines, sentences, and paragraphs line must be explicitly
the secondary storage or sent to some destination in the
process of loading a device dniver's code and static Program-oriented editors operate on elements such as
during subsequent revISion,
data into memory so that the driver is registered with specified by line number or by some pattern context. For network, such as a printer or some remote host.
1dentifiers, key words and statements. editor in early MS-DOS systems.
the system. example, edlin 2) Appropriate Format for Storing the Document in
3) Providing I/O services for the driver The idea here is similar to line
Editing phase involves 2) Stream Editors: File in Secondary Storage: The most natural way to
stream
editor, but the entire text is treated as Single
a
document is planar layout of the
Drivers for different types of devices have different sets of
a Insert b. Delete visualise a as a
of characters. Hence the location for revision cannot information, within some bounded space. Thus, one
C. Replace d. Move
entry points according to the kinds of operations the
Cut be specifiedusing line numbers. Locations for possible format to save (store) the document in
devices perform. A driver for a memory-mapped e Copy revision are either specified by explicit positioning or
secondary storage is to save the attributes of each
character-oriented device, while a block driver does not Paste, etc. context. Forexample, sed in visible point (pixel) by traversing the layout in some
support this entry. by using pattern
Unix/Linux. Line editors and stream editors are order, say, left-to-right lines trom top to bottom.
Types of Editors
The editors may be classified into two types as given suitable for text-only documents, However, this is not the done for obvious reasons. For
TEXT EDITORS below: 3) Screen Editors: These allow the document to be textual information, there are widely used eode-sets
) Text Editors: A text editor is a program, which viewed and operated upon as a two dimensional (C.g, ASCIl, EBCDIC, ISCI, Unicode, ete.) that are
plane, of which a portion may be displayed at a time Lused to encode the information. These code sets also
Ques 22) What is the
various types of editors.
meaning of editing? Def+ne allows the user to create the source progranm in the
contain codes for white spaces and new-line, and
form of text into the main memory.
Generally theuser Any portion may be specified for display and location
Or prepares HLL program or any sOurce program. 1he for revision can be specified anywhere within the hence most textual intormation can be conveniently
What is editing? List the steps involved in document- emacs, etc, represented preserving the desired layout. Many
text
Creation, cditing modification, deletíon, updating o displayed portion, For example, vi,
editing process in an interactive user-computer document or files can be done with the help of the text 4) Word Processors; Provides additional features to editors allow the appearance (script, size, colour and
dialogue. editor. The scope of the editing is limíted to the text basic screen editors, Usually support non-textual style) of text to be specified by the user, From the
only POint of yiew of storing such variations of appearance
C-85
Semester TP Solved Series (System (Module 5)
C-84 B.Tech. Fifth Software) KTu SMacro
Procesors
wn. pattem search, etc.), in which case the Thus some kind of combination of array and linked list
of text. this is usSually achieved key. Text devices wilh
arow
(cursor) -down,
by stoning cxtri Simulate locator devices, v nbe p potiOns must be performed tor that portion. Thus may have to be used. For cxample, the entries of an array
used to
information descnibing the appearancc along wth p oI the size of the buffers for each Jine of the
actual tex Thus in secondary storage, the iie
the devices, which transliate spoken worde o r Drogram should keep track may pont to individual
document The buffer for a line may either be array or
textual cquivalents, may prove to be the ters window, and
the bOundaries of the current
to a document contains the textual
coTesponding
informaton as well attributes of the
devices of the future. Voice recognizers are currep
d e d portion in tems of offsets Irom some fixcd point
first
Iinked lists (with, say, a word in each node). For very
( s u c n as line number of the idea to hold the
as
text, available for command input onsome systems document Targe documents it may not be a good
sometimes called metadata that controls the the
structure for entire document in such buffers since only a small portion
displayed lines, elc.). The chojce of datasince
in
of the text in output medium. if n) Button or ChoIce Devices: These genera
appearance Similarly, image (Duiers) 15 important, it has to is displayed at a time and editing operations for a
the document has to contain non-textual information, interrupt or set a system 1ag, usually he memory
invocation of an associalcd application-nr
insertion
efficient and deletion, while allowing the reasonable duration are likely to be in the neighbourhood
that too iS embeddecd using suitable metadata. support
of the document
Irom small to
to very Jarge.
vary of the displayed portion.
action. Such devices typically include a set of e
3) Eicient Transfer of Information between the User
special function keys on an alpha
anumeric each row
containing
nple 2-dimensional array with
a
Interface and the File in Secondary Storage: Theto keyboard or on the display itself. 4 simple
In such situations, a text editor may load only the required
ine of text,
may not sujt
1or
obvious reasons (what are the portion of the document into memory buffers, but be able
uscr interface of a text cditor has to give emphasis
ons?). A linked Jist may 1acilitate easy insertion and
the visual appearance of the portion of the document im) Locator Devices: These are two-dimentine
a single node in the
toload any other portion as and when required. Ittoo
needs
it
to
deletion. but having
Cach
leter in be remembered that in the memory image is
that 1s
any time, and convenience of
displayed at the analog-to-digital converters that position a cu memory. Also, user
user to perform editing operations and viewing the symbol on the screen by observing the user finked list may
be wastetul
oI essential to represent thc metadata corresponding to. the
document On the other hand the format in which the movement of the device, 1he most common s conmands sSuch as page-up, pag-doWn, etc., may become different portions of the document.
document is stored in the secondary storage basically devices for editing applications arC the mouse and inefficient.
an unambiguous, static, and non-vi1sual the data tablet. Locator devices usually
provides the structure of typical editor wíth the help of diagram.
model of the document. Thus the text editor has to incorporate one or more butons that can b Used Oues 27) Explain
Or
convert the user input into the file fomat, and file to specify cditing operations.
into the format. This conversion is one the structure of a text editor with the help of a diagram. (2017 [05))
fomat display
of the basic requiretnents for the 1ext editor design. 2) Output Devices: Formerly limited in ringe, output
Explain Or
devices for editing are becoming more diverse. The
Draw the structure
of a Typícal Text Editor and describe the functions of each block. (2018[08)
output device lets the user vicw the clements being Or
Ques 25) Discuss about the criteria for the user
interface design.
edited and the results of the editing operatioh. The fint With the help ofa diagram describe the structure of a text editor. (2021(10))
Or output devices were teletypewnters and othercharacter Or
printing terminals that generatcd output on paper. Explain the structure of text editor wíth the help of diagram. (2019[06)
Write notes on the user interface of a text editor.
(2017 [05)) 3) Interaction Language: The interaction languageofa Ans: Structure of Text Edítor
Or texteditor is generally one of several common types Most text editors have a structure similar to that shown in figure 5,16, regardless of the particular features they offer and
Describe the user interfaces used in a text
editor.
(2019|05))
The user communicates with the
editor by typingtext the computers on which they are implemented
strings both for command names and for operands
Ans: User Interface These strings sent to the Editüing Editing
Conceptual model of the editing system provides an casily
are
editor and are usually Component Buffer
echoed to the output device. Typed specification often
understood abstraction of the target document and its Tequires the user to remember the exact form ofall
clements. For example, Line editors simulatcd the commands, least their abbreviations If the
or at
Editing
sworld of the key punch - 0 characters, single line or an Filter
Command language 1s complex, the user must
integral number of lines, Screen editors Document is continually refer to a manual or an on line help
represcnted as a quarier-plane of text lines, unbounded
function for a description of less frequently used Main
both down and to the nght. Traveling
Commands. In addition, the Memory
typing reqUired can D Compone
time consuming, especially for
The user interface (U) is concerned with, the input inexperienced users
The function-key interface addresses these
devices, the output devices and. the interaction language Vicwing
deficiencies. Here each command has assocated wiln InputCommand
The input devices are used to enter text elements of being marked
Filter
it a the user's
key on keyboard, Languager
cdited, to enter commands. The output devices, lets the Processor
user view the ciements being edited and the results of the
editing operations and, the interaction language provides
Ques 26) Discuss the desígn of an Edítor, Viewing Viewing
Component Bufer
communication with the editor. A user interface plays
Ans: Design of an ditor
important role in simplifying the interaction of a user with
The structure of a text editor depends largely onthe yp Paging
an application. UI functionalities have two important routines
of
aspects. User interface is concerned with the input devices, editing features and displaying capabilitiesthatare1o Ouiput Devices Display File
the output devices, and the interaction languape of the Supported. To implement the displaying capabilite, Componcne
semantucs of the metadata that may be presen System
system, which are 2s follows:
document nle necds to be implernented as display Control
1) Input Devices: These are uscd to enier elements of
For Dala
the text being edited, to euter comnands, and to example, if the netadata
implies a particu Figure 5,16; Editor Structure
De Used for a
designate cditable elements. These devices, as used segment of text, editor shou
nethods affect that
to
colour ne
with editons, cun be divided into there categories, for the particU major components of
tert Siice at
time only a finite
a
gd docun editors are 2) Editing Component: In a the start
editing doeument.
which are as folows portion o 0and Langunge Processor: The command of the area to be edited is determined by the current
such actíons are to betaken for a portin
ofthe layed,
i)Text or String Devices: These are typically uige processor accepts input from the user's nput editing pointer maintained by the cditing component
information the file.
ypewriter-ike keytrds on wfuch a uer prees
pecly sote other
However,
in
age CeS, and unalyzes the 1okens and syntactic which is the collection of modules dealing with
and releases keys, sending a unigue c e for cachi portion
displayed (hrouy
to be structure of the commands, editing tasks.
C-86 B.Toch. Fifth Semester 7P Sofved Series (ystem Sotware) (Module 5) CR7
Phxeswrs
MAn
3) afes on the debuggmg inctions and capabilities
Travelling Component: The travelling component ot 2) Printing to log files writes of database. In some debugger systems, it wil
the editor actualy
perfomms the setting of the curent 5) Spnnkling the code with assertions
interactive
debugging ystenm (2017 [051)) be enough simply to cnsure that a read qucry never
editing and viewing pointers, and thus determines the fan Or
4 UsinS post-mortem dumps nd ittempts to read data which is not yet available in
point at which the viewing and/or 5) Having programs that provzde function call stacks the functions capabilities of an in others, it may be necessary to ensure that
begins.
editing filtening
Feminaton
0n
ihe
Debugging System. (2018[06)
database;
what is read is the last complete write done by
Interactiyd
4)
Viewing Component: 6) Profiling debugger client. Onc method of coordinating reads
start of the area to
In viewing a document. the
7) Heap checking Debugging Funetions and Debugging Capabilities and writes is to treat each read and write as a
be viewed is determined by the
tools
ATS:
ints highlight the debugging unctions and
curent viewing pOinter. Th1s S) System call tracing transaction and to use standard dátabase transaction
pointerIs maintained by 9) Interacive source-level debugging
the viewing component of the editor.
which Is a
nubilhues provide functions such as processing techniques where consistency
10) Reverse erecution etc. Debugging system should
collection of modules responsible for determining the tracing and traceback. requirements are less stringent, the overhead of
next view. to track the flow of execution transaction processing can be avoided and sufficient
The basic principles of debugger are: Tricing can bemodifications.
used It can also coordination of reads and writes may be achieved by
5) Display Component: be based on
This produces a
display the
by ) Heisenberg Principle: This pnnciple says that the logic and data ordering the writes such that informatron which a
mapping the buffer to a rectangular subset of conditional expressions.
debugger must intrude on the debuggee in a minimal
Sereen. usualy called a window. Traceback can shoW the path by which the current given record in the data base depends on is written to
way the
6) Editing and iewing Buffers: The editing and
statement was reachned. can also show which database before therecord itself is written, thereby
viewing buffers. while independent, can be related in
2) Truthful Debugging: 1he
so the programmer always trusts it
debugger must be truthful statements have modified a given vamable or parameter. ensuringthat all the information needed to respond to
a query for which the given record is a result is in the
many ways. In the simpiest case, they are 1dentical - Debugging system have a good program display database the time the record itself can be
capabilities. It must be possible to display the program by quenied
the user edits the material
directiy on the screen. On
3) Providing Context Information: The debugger
the other hand. thec editing and should provide the program context heing debugged, complete with statement nunmbers. 2) Debugger Client: Debugger client is a debugger
viewing buffers may information The system should saveall the debugging specifications is cxecuting
be completely disjoint
duringSource
debugging. Program context information are across such a recompilation, so the user does not need to
which a program being debugged in
debugger process. For purposes of the present
i) code. m) Stack back-track, ) Variable
7) Viewing and Editing Filter: This component tilters discussion, a debugger client may be any entity which
values, iv) Thread infomation reissue all ofthese debugging commands,
the document to generate a new vicwing buffer based
Debugging system must be sensitive to the specific executes a computer program in such a fashion that
on the current Viewing pointer as well as on the
viewing tlter parameters. his viewing bufferis then
Ques 30) Discuss the basic operations supported by a
language being debugged so that procedural,
anthmetic and conditional logic can be coded in the
information about the execution which would not
normally be available to a user of the program
passed to the display componcent of the editor. debugger.
Ans: Basic Operat.ons Supported
syntax of that language.
becomes available. Thus, debugger client may be
A debugger
by a Debugger The debugger should be able to switch its context implemented expressly for system or it may be any
provides an nteractive interface to the kind of existing interactive debugger. Debugger client
DEBUGGERS programmer 1o control the execution of the program and
observe the proceedings. The program
when program wrntten in one language calls a
a
program written in a different language. may have access to both the source code and object
Ques 28) What do you mean by debugging? Explain. be debugged is provided as an input to
(executable file) to A debugging system must be able to deal with
code for program. Debugger client may interpret source
basic operations supported
the debugger. The optimised code. Application code used in production code, but more generally, it will execute object code
Ans: Debugging by a debugger are:
Debugging means iocating (and then removing) bugs 1)Breakpoints: Setting breakpoints at various positions in
environments is usually optimised.
and use
source code to make debug info more
understandable to the user of the debugger
the
fauilts in programs). in the entire process of program program. The breakpoints are points in the program
at which the programmer wishes to
Ques 32) What are the different components of a Debug information obtained from source code and by
development errors may occur at vanous stages and efiorts suspend normal debugging system? Explain. means of execution of object code is wnitten to debug
execution of the program and perform
to detect and remove them may also be made at various other tasks. database by means of update queries to debug database
2
stages. However. the word debugging is usually in context
of errons that manidest while running the program dunng
Examining Values of Different Memory Locations:
When the
Ans: Components of Debugging System
Server In
some embodiments there may be more than
execution of a program is suspended, the he major components of debugging system are: one debugger client; for example, a progrummer may
or during actual use. The
testing most common steps taken contents
of specified memory locations can be
Cxamined. This includes local
Debugging Database System: Debugging database want to watch the behavior of two closely-cooperating
n debuggng arc to cxumine the of control during
fiow variables (usually on
the stack), function parameters,
system contains a database with persistent debugging programs, or there may be debugger chents specializedd
exccution of the program. examine values of vaniables at and global (extem) mormation (a... n) for a variety of executions of Tor different progrumming languages or tor ditlerent
different points in the program. cxamine the values of vaniables. programs, The term persistent is used here in to mean
parametes passed to functions and values retumed by the programming problems
3) Examining the Contents of the program Stack: Ine hat the debugging information remains available in
functions, examine the function call sequence, etc. To 3) User Interface Client: Each user interface client
overcome several such drawbacks of debugging by
COnients the program stack reveals informaton
he database after execution of the program has receives inputs from a user, responds to some inputs
related to the function call sequence that is active a ceased. Database is managed by debug database
nserting extra statements in the program. there is various
that moment by making a read query (Rquery) for debug data buse
erver, which responds to from the other
queries
kind of tool calied debugger that heips in debugging ponents of debugging system by wriling to or server, and responds to the resuls of Rquery by
programs by giving the programmer some control over the Depositing Values in Different
Memory LOcatios formatting the results and providhng the formatted
execution of the program and some means of examining Whiie the Cxecution of the debugged program 1s cading from debug information as required by the results to the user as formattecd output The foms o
and modifying different program variabies during runtine underway (yet to start or suspended at a breakpoint. ucry, Conceptually, debug data base server has two
cls of clients: the inpuls received and the outputs provided by a
E
programmer can deposit any value in the memop given intertace client depends on the kind of
Debugger client which provides update
Ques 29) Discuss Interactive Debugging System Ocauons coTesponding to the program variahies queries interactive intertace enployed by the user. Again, the
paramelersto subroutines, and
processor rogstetn otaining debug information todatabuse, nd interactive intertace may be any presently existing or
Ans:Interactive Debugging Systems interface clients which
Debugging is a methodical process of finding ad reducing e more
or
user future interactive intertace. Debugger cliçnt and the
ues 31) Describe the important functions and provide gueries that read selected debug user intertace clients turther communicale with euch
the aumber of debugs, or defects in a computer program. capabilities of an interactive debugging system.
An interactive debuEging systcm pruvides programmers nformation from database, other by means of control channel, which may be any
Or arrangement which pemuts ranster of nessages
with faciliues that aid an the esting und debugging of Eaplain the data base system may b0 Speciay
programs The approaches to debuggng ae
debugging functions and debua ciented for system or it may be one of the many
between debugger client and a user iniecface client
1) Prn stalemcns
capabilities User intertace client uses control chaRnel o tansler
Or cCal database systems. One ofthe functions of debugger cOmmands to debugtges wh
C-88
B.Tech, Fifth Semester IP Solvea Seriess (System S 5)
(System Software) Proces
(Module
C-89
debugger client
KTu Macro
shown in the following table. The "What" boxes
uses control channel to transter 3) Backtracking here), one attempt to eliminate all but one of the
debugger event
messages to user interface cient. For Or list the general synproms, the "Where" boxes
example, a first debugger command may instruct the possible causes, If all are climinated, additional data
List and explain the difterent debugging technion describe where tne 5ymptomsS were observed, thee
debugger conceming the kinds of information it 1s to Vhen" boxes list anything that is known about are needed (cg, by devising additional test cases) to
output, while another may instruct the
stop execution of
debugger to
Ans: Methods/Techniques Used for Debuggino
2019(05) the times that the symptoms occur, and the "To
.What Extent boxes describes the scope and

devise new theories, If more than one possible cause


remains, the most probable cause (the prime
program at a
predetermined point. hypothesis) is selected first.
Following are the method used for debugging: magnitude of the symptoms. Notice the "Is" and
Ques 33) List out the criteria that should be 1) Debugging by Brute Force: The most com ii) Refine the Remaining Hypothesis: The possible
user interlace of
met by the "Is Not columns. They describe the
an Ei+cient Debugging System. least effective method of program debugoin and contradictions that may eventually lead to a cause at tothis point might be correct, but itis
(2018[04) "brute force". It requires little thought and isi h y hypothesis about the error. unlikely he specific enough to pinpoint the
eTor, Hence, the next step is to use the available
mentally taxing of all the methods. The hmCat
Ans: Criteria
Required to Meet by User Interface
Is Is Not clues to refine the theory to something more
Efficient Debugging System
of an methods are
charactenzed by either debuggino What specific.
1) User friendly. memory dump; scattenng pnnt statements throuph Where
the program, or debugging with automated debusU 1) Prove the Remaining Hypothesis: This vital
2) Use full screen
display and When_ step is identical to the fourth step in the induction
3) Use menu bars: windowing display. tools. Using a
memory dump to
try to find ero To what Extent |
suffers from the following drawbacks: method.
1) Menus should have the Collect More
heading of the task. i) Establishing the
corespondence sto between ii) Devise a Hypothesis: The next steps are to study
11) Possible to go directiy
to menus and it should not locations and the vanables in the source Droo the relationships among the clues and devise,
entire hierarchy. is difficult
4) Command Language: using the patterns that might be visible in the
Cannot
ii) Massive amounts or
daa, most Of which structure of the cues, one or more hypotheses
i) It must be clear, logical, simple is
syntax. irelevant, must be dealt with. about the cause of the error. If one cannot devise Refine
ii) Should minimise punctuations, eg: ).7,etc. Enumerate Prove
i) A dump shows only the statie state of the a theory, more data are necessary, possibly possible Use process remaining remaining
5) Available Help Facility. Causes Cmnation
hypothesis hypothesis
program at only one instant in time. The obtained by devising and executing additional
Ques 34) Explain the dynamics of the program (1.e., State changes over test cases. If multüple theories seem possible, the
other parts of the system.
relationship of debugger with time) are needed to find most errors. most probable one is selected first. can
iv) The dump is rarely produced at
the exact-time of iv) Prove the Hypothesis: A major mistake at this thc ei
Ans: the error. Hence the dump
Relationship with Other Parts of the System does not show the point, given the pressures under which debugging
The mportant requrement fo an interactive program's state at the time of the error.
debugger 15 Figure 5.18: Deductive Debugging Process
that it always be v) formal procedure exists for
No is usually performed, is skipping this step by
available of an error analyzing a
finding the cause jumping to conclusions and attempting to fix the
) Debugger must appear as part of the run-time storage dump. problem. However, it is vital to prove the
environment and an
integral part of the system. 2) Debugging by Induction: Many errors can be found reasonableness of the hypothesis before
4) Debugging by Backtracking: For small programs,
2) When an error is discovered, immediate debugging the method of backtracking is often used effectively in
by using disciplined thought process without ever
a
proceeding.
must be possible. locating eTOrs. To use this method, start at the place
going near the computer. One such thought
3) The debugger must communicate and process is Cannot
other
cooperate with induction, where one proceeds from
the particulars to Locate
in
program where an incorrect result was produced
the
operaling system components such as interactive the whole. By
starting with the symptoms of the errOr, PertinentH Organize the
Data
Study their
Prelationships
Devise a
hypothesis
and go backwards in the program one step at a time,
subsystems. possibly in the result of one or more test cases, and mentallyexecuting the program in reverse order, to
4) Debugging is more important at production time than data derive the state (or values of all variables) of the
it
looking for relationships among the symptoms, the Can
is
application- development time. When an
at
eror often uncovered. The
is
program at the previous step. Continuing in this
application fanls during a production run, work illustrated in figure 5.17 and
induction process 15 Prove the fashion, the eror is localized between the point where
dependent on that application stops. described by Myers as bypothesisCan
5) The debugger must also exist in a way that 1s
follows: Can not the state of program was what was expected and
the
1) Locate the Pertinent Data: the first point where the state was not what was
consistent with the security and integrity components
A major mistake
of the system.
made when
debugging a
program 1s failing lo FEx the error expected
take account of all available
6) The debugger must coordinate its activities with those
about the problems. The
data or symploms 5) Debugging by Testing: The use of additional test
of existing and future language compilers and
first step 15 the Figure 5.17: Inductive Debugging Process Cases is another very powertul debugging method
enumeraton of all that is 5)
interpreters.
known about what the Debugging By Deduction: An alternate thought which is often used in conjunction with the induction
program did correctly and what it did incomecuy process that of deduction, is a process of proceeding method to obtain information needed to generate a
(1.e., the
Ques 35) Discuss the various methods of debugging. symptoms that led one to believe that au irom some general theories or premises, using the hypothesis and/or to prove a hypothesis and with the
eror exists). Additional valuable clues are deduction method to eliminate suspected causes,
Or
provided by similar, but processes of elimination and refinement, to arrive at a
How induction and deduction methods are used for
do not
different, test cases tnal conclusion. This process is illustrated in figure 5.18 refine the remaining hypothesis, and/or prove a
cause the and also described hypothesis. The test cases for debugging differ from
debugging? symptoms to appear, by Myers as follows;
Or 1) Organise the Data: Remembering that induciou Enumerate the Possible Causes or Hypotheses: those used for integration and testing in that they are
How backtracking is used for debugging? mplies that one is progressing from the
iculas The first ep is to develop a list of all more specific and are designed to explore a particular
Or to the conceivable causes of the error. They need not be input domain or internal state of the program.
general, the second step is the structurng
Describe any two commonly used debugging methods he
pertinent data to Complete explanations; they are merely theories
to allow one observe pale hrough which one can structure and analyze the Test cases for integration and testing tend to cover
the sear for
(2017 [05) of particular importance is
available data. many conditions in one test, wlhereas test cases for
Or
Explain the following methods of debugging: (2020[10]) ne
occurs on when
Contradictions (i.e., "the errors
Use the Data to Eliminnte Possible Causes: By a debugging tend to cover only one or a very few
pilot perform a left tun while )
1) Induction climbing conditions. The former are designed to detect the error
Careful analysis of the data, particularly by looking
2) Deduction Aparicularly useful organizational technigu
data s
1or contradictions (the previous table could be used
in the most efficient manner whereas the latter are
that can be designed to isolate the ceror most efficiently
used to structure
the availa

You might also like