Sunteți pe pagina 1din 69

CS2308 SYSTEM SOFTWARE LAB

Prepared By,
R.Uma,
Lecturer, CSE
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
CS2308 SYSTEM SOFTWARE LAB L T P
C
0 0 3 2
(Using C)
1. Implement a symbol table with functions to create, insert, modify, search, and
display.
2. Implement pass one of a two pass assembler.
3. Implement pass two of a two pass assembler.
4. Implement a single pass assembler.
5. Implement a two pass macro processor
6. Implement a single pass macro processor.
7. Implement an absolute loader.
. Implement a relocating loader.
!. Implement pass one of a direct"lin#ing loader.
1$. Implement pass two of a direct"lin#ing loader.
11. Implement a simple te%t editor with features li#e insertion & deletion of a character,
word, and sentence.
12. Implement a symbol table with suitable hashing
'(or loader e%ercises, output the snap shot of the main memory as it would be, after the
loading has ta#en place)
TOTAL=45 PERIODS
R!"i#$n% &'# ( )(%*+ '& 30 s%",n%s
Ds*#i-%i'n '& E!"i-$n% . /"(n%i%0 R!"i#,
1. *ardware + ,entium ,- .es#tops " 3$ /os.
2. 0oftware + 1urbo - '(reely download) " 2ultiuser
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
LIST OF EXPERIMENTS
S.NO TITLE PAGE NO
1 I$-1$n% ( s0$)'1 %()1 2i%+
&"n*%i'ns %' *#(%3 ins#%3 $',i&03
s(#*+3 (n, ,is-1(04
I$-1$n% -(ss 'n '& ( %2' -(ss
(ss$)1#4
! I$-1$n% -(ss %2' '& ( %2' -(ss
(ss$)1#4
" I$-1$n% ( sing1 -(ss (ss$)1#4
# I$-1$n% ( %2' -(ss $(*#'
-#'*ss'#
$ I$-1$n% ( sing1 -(ss $(*#'
-#'*ss'#4
% I$-1$n% (n ()s'1"% 1'(,#4
& I$-1$n% ( #1'*(%ing 1'(,#4
' I$-1$n% -(ss 'n '& ( ,i#*%.
1in5ing 1'(,#4
1( I$-1$n% -(ss %2' '& ( ,i#*%.
1in5ing 1'(,#4
11 I$-1$n% ( si$-1 %6% ,i%'# 2i%+
&(%"#s 1i5 ins#%i'n 7 ,1%i'n '& (
*+(#(*%#3 2'#,3 (n, sn%n*4
1 I$-1$n% ( s0$)'1 %()1 2i%+
s"i%()1 +(s+ing
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
EXPT NO 1
Implement a symbol table wt! "#n$tons to $%eate& nse%t& mo'"y& sea%$!& an' 'splay(
AIM )
To write a C program to implement Symbol Table
A*+,r-t.m )
1. Start the program for performing insert, display, delete, search and modify option
in symbol table
2. Define the structure of the Symbol Table
3. Enter the choice for performing the operations in the symbol Table
. !f the entered choice is 1, search the symbol table for the symbol to be inserted. !f
the symbol is already present, it displays "Duplicate Symbol#. Else, insert the
symbol and the corresponding address in the symbol table.
$. !f the entered choice is 2, the symbols present in the symbol table are displayed.
%. !f the entered choice is 3, the symbol to be deleted is searched in the symbol
table. !f it is not found in the symbol table it displays "&abel 'ot found#. Else, the
symbol is deleted.
(. !f the entered choice is $, the symbol to be modified is searched in the symbol
table. The label or address or both can be modified.
S,urce C,de pr,+ram -/ c -mp*eme/t 0ym1,* ta1*e
) include *stdio.h+
) include *conio.h+
) include *alloc.h+
) include *string.h+
) define null ,
int si-e.,/
0oid insert12/
0oid del12/
int search1char lab342/
0oid modify12/
0oid display12/
struct symbtab
5
char label31,4/
int addr/
struct symtab 6ne7t/
8/
struct symbtab 6first,6last/
0oid main12
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
5
int op/
int y/
char la31,4/
clrscr12/
do
5
printf19:nS;<=>& T?=&E !<@&E<E'T?T!>':n92/
printf191. !'SEAT:n92/
printf192. D!S@&?;:n92/
printf193. DE&ETE:n92/
printf19. SE?ACB:n92/
printf19$. <>D!C;:n92/
printf19%. E'D:n92/
printf19Enter your option D 92/
scanf19Ed9,Fop2/
switch1op2
5
case 1D
insert12/
display12/
breaG/
case 2D
display12/
breaG/
case 3D
del12/
display12/
breaG/
case D
printf19Enter the label to be searched D 92/
scanf19Es9,la2/
y.search1la2/
if1y..12
5
printf19The label is already in the symbol Table92/
8
else
5
printf19The label is not found in the symbol table92/
8
breaG/
case $D
modify12/
display12/
breaG/
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
case %D
breaG/
8
8
while1op*%2/
getch12/
8
0oid insert12
5
int n/
char l31,4/
printf19Enter the label D 92/
scanf19Es9,l2/
n.search1l2/
if1n..12
5
printf19The label already e7ists. Duplicate cant be inserted:n92/
8
else
5
struct symbtab 6p/
p.malloc1si-eof1struct symbtab22/
strcpy1pH+label,l2/
printf19Enter the address D 92/
scanf19Ed9,FpH+addr2/
pH+ne7t.null/
if1si-e..,2
5
first.p/
last.p/
8
else
5
lastH+ne7t.p/
last.p/
8
si-eII/
8
8
0oid display12
5
int i/
struct symbtab 6p/
p.first/
printf19&?=E&:t?DDAESS:n92/
for1i.,/i*si-e/iII2
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
5
printf19Es:tEd:n9,pH+label,pH+addr2/
p.pH+ne7t/
8
8
int search1char lab342
5
int i,flag.,/
struct symbtab 6p/
p.first/
for1i.,/i*si-e/iII2
5
if1strcmp1pH+label,lab2..,2
5
flag.1/
8
p.pH+ne7t/
8
return flag/
8
0oid modify12
5
char l31,4,nl31,4/
int add, choice, i, s/
struct symbtab 6p/
p.first/
printf19Jhat do you want to modifyK:n92/
printf191. >nly the label:n92/
printf192. >nly the address of a particular label:n92/
printf193. =oth the label and address:n92/
printf19Enter your choice D 92/
scanf19Ed9,Fchoice2/
switch1choice2
5
case 1D
printf19Enter the old label:n92/
scanf19Es9,l2/
printf19Enter the new label:n92/
scanf19Es9,nl2/
s.search1l2/
if1s..,2
5
printf19'> such label92/
8
else
5
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
for1i.,/i*si-e/iII2
5
if1strcmp1pH+label,l2..,2
5
strcpy1pH+label,nl2/
8
p.pH+ne7t/
8
8
breaG/
case 2D
printf19Enter the label whose address is to modified:n92/
scanf19Es9,l2/
printf19Enter the new address:n92/
scanf19Ed9,Fadd2/
s.search1l2/
if1s..,2
5
printf19'> such label92/
8
else
5
for1i.,/i*si-e/iII2
5
if1strcmp1pH+label,l2..,2
5
pH+addr.add/
8
p.pH+ne7t/
8
8
breaG/
case 3D
printf19Enter the old label D 92/
scanf19Es9,l2/
printf19Enter the new label D 92/
scanf19Es9,nl2/
printf19Enter the new address D 92/
scanf19Ed9,Fadd2/
s.search1l2/
if1s..,2
5
printf19'> such label92/
8
else
5
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
for1i.,/i*si-e/iII2
5
if1strcmp1pH+label,l2..,2
5
strcpy1pH+label,nl2/
pH+addr.add/
8
p.pH+ne7t/
8
8
breaG/
8
8
0oid del12
5
int a/
char l31,4/
struct symbtab 6p,6L/
p.first/
printf19Enter the label to be deleted:n92/
scanf19Es9,l2/
a.search1l2/
if1a..,2
5
printf19&abel not found:n92/
8
else
5
if1strcmp1firstH+label,l2..,2
5
first.firstH+ne7t/
8
else if1strcmp1lastH+label,l2..,2
5
L.pH+ne7t/
while1strcmp1LH+label,l2M.,2
5
p.pH+ne7t/
L.LH+ne7t/
8
pH+ne7t.null/
last.p/
8
else
5
L.pH+ne7t/
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
while1strcmp1LH+label,l2M.,2
5
p.pH+ne7t/
L.LH+ne7t/
8
pH+ne7t.LH+ne7t/
8
si-eHH/
8
8
RESULT) Thus a symbol table is implemented in C .
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
EXPT NO
I$-1$n% -(ss 'n '& ( %2' -(ss (ss$)1#4
AIM
To implement pass one of a two pass assembler.
ALGORIT2M
1. >pen the files fp1 and fp in read mode and fp2 and fp3 in write mode
2.Aead the source program
3. !f the opcode read in the source program is ST?AT, the 0ariable location
counter is initiali-ed with the operand 0alue.
. Else the location counter is initiali-ed to ,.
$. The source program is read line by line until the reach of opcode E'D.
%. ChecG whether the opcode read is present in the operation code table.
(. !f the opcode is present, then the location counter is incremented by 3.
N. !f the opcode read is J>AD, the location counter is incremented by3.
O. !f the opcode read is AESJ, the operand 0alue is multiplied by 3 and then the
location
counter is incremented.
1,. !f the opcode read is AES=, the location counter 0alue is incremented by
operand 0alue.
11. !f the opcode read is =;TE, the location counter is auto incremented.
The length of the source program is found using the location counter 0alue.
S,urce C,de pr,+ram -/ c pa00 ,/e ,3 a t4, pa00 a00em1*er.
) include *stdio.h+
) include *conio.h+
) include *string.h+
0oid main12
5
char opcode31,4,mnemonic334,operand31,4,label31,4,code31,4/
int locctr,start,length/
C!&E 6fp1,6fp2,6fp3,6fp/
clrscr12/
fp1.fopen19input.dat9,9r92/
fp2.fopen19symtab.dat9,9w92/
fp3.fopen19out.dat9,9w92/
fp.fopen19optab.dat9,9r92/
fscanf1fp1,9EsEsEs9,label,opcode,operand2/
if1strcmp1opcode,9ST?AT92..,2
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
5
start.atoi1operand2/
locctr.start/
fprintf1fp3,9:tEs:tEs:tEs:n9,label,opcode,operand2/
fscanf1fp1,9EsEsEs9,label,opcode,operand2/
8
else
locctr.,/
while1strcmp1opcode,9E'D92M.,2
5
fprintf1fp3,9Ed:t9,locctr2/
if1strcmp1label,96692M.,2
fprintf1fp2,9Es:tEd:n9,label,locctr2/
rewind1fp2/
fscanf1fp,9Es9,code2/
while1strcmp1code,9E'D92M.,2
5
if1strcmp1opcode,code2..,2
5
locctrI.3/
breaG/
8
fscanf1fp,9Es9,code2/
8
if1strcmp1opcode,9J>AD92..,2
locctrI.3/
else if1strcmp1opcode,9AESJ92..,2
locctrI.1361atoi1operand222/
else if1strcmp1opcode,9AES=92..,2
locctrI.1atoi1operand22/
else if1strcmp1opcode,9=;TE92..,2
IIlocctr/
fprintf1fp3,9Es:tEs:tEs:n9,label,opcode,operand2/
fscanf1fp1,9EsEsEs9,label,opcode,operand2/
8
fprintf1fp3,9Ed:tEs:tEs:t:Es:n9,locctr,label,opcode,operand2/
length.locctrHstart/
printf19The length of the program is Ed9,length2/
fclose1fp12/
fclose1fp22/
fclose1fp32/
fclose1fp2/
getch12/
8
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
INPUT FILES
INPUT.5AT
66 ST?AT 2,,,
66 &D? C!PE
66 ST? ?&@B?
66 &DCB CB?AQ
66 STCB C1
?&@B? AESJ 1
C!PE J>AD $
CB?AQ =;TE CRQR
C1 AES= 1
66 E'D 66
OPTAB.5AT
ST?AT
&D?
ST?
&DCB
STCB
E'D
>ST@ST C!&ES
>ST.D?T
66 ST?AT 2,,,
2,,, 66 &D? C!PE
2,,3 66 ST? ?&@B?
2,,% 66 &DCB CB?AQ
2,,O 66 STCB C1
2,12 ?&@B? AESJ 1
2,1$ C!PE J>AD $
2,1N CB?AQ =;TE CRQR
2,1O C1 AES= 1
2,2, 66 E'D 66
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
S;<T?=.D?T
?&@B? 2,12
C!PE 2,1$
CB?AQ 2,1N
C1 2,1N
RESULT)
Thus a C program was written to implement @?SS >'E of a two pass
assembler
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
EXPT NO !
I$-1$n% -(ss %2' '& ( %2' -(ss (ss$)1#4
AIM )
To implement pass two of a two pass assembler.
ALGORIT2M )
1. Start the program
2. !nitiali-e all the 0ariables
3. >pen a file by name
fp1.fopen19assmlist.dat9,9w92/
fp2.fopen19symtab.dat9,9r92/
fp3.fopen19intermediate.dat9,9r92/
fp.fopen19optab.dat9,9r92/
. Aead the content of the file
$. !f opcode is =;TE
if1strcmp1opcode,9=;TE92..,2
T.e/
fprintf1fp1,9Ed:tEs:tEs:tEs:t9,address,label,opcode,operand2/
Else if opcode is J>AD
else if1strcmp1opcode,9J>AD92..,2
t.e/
fprintf1fp1,9Ed:tEs:tEs:tEs:t,,,,,Es:n9,address,label,opcode,operand,a2/
Else perform
else if11strcmp1opcode,9AES=92..,21strcmp1opcode,9AESJ92..,22
fprintf1fp1,9Ed:tEs:tEs:tEs:n9,address,label,opcode,operand2/
if it is not math anything
else
fprintf1fp1,9Ed:tEs:tEs:tEs:tEd,,,,:n9,address,label,opcode,operand,code2/
%. Cinally terminate the of pass two of pass two assembler
S,urce c,de pr,+ram -/ c pa00 t4, ,3 pa00 t4, a00em1*er
)include*stdio.h+
)include*conio.h+
)include*string.h+
)include*stdlib.h+
0oid main12
5
char a31,4,ad31,4,label31,4,opcode31,4,operand31,4,mnemonic31,4,symbol31,4/
int i,address,code,add,len,actualTlen/
C!&E 6fp1,6fp2,6fp3,6fp/
clrscr12/
fp1.fopen19assmlist.dat9,9w92/
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
fp2.fopen19symtab.dat9,9r92/
fp3.fopen19intermediate.dat9,9r92/
fp.fopen19optab.dat9,9r92/
fscanf1fp3,9EsEsEs9,label,opcode,operand2/
if1strcmp1opcode,9ST?AT92..,2
5
fprintf1fp1,9:tEs:tEs:tEs:n9,label,opcode,operand2/
fscanf1fp3,9EdEsEsEs9,Faddress,label,opcode,operand2/
8
while1strcmp1opcode,9E'D92M.,2
5
if1strcmp1opcode,9=;TE92..,2
5
fprintf1fp1,9Ed:tEs:tEs:tEs:t9,address,label,opcode,operand2/
len.strlen1operand2/
actualTlen.lenH3/
for1i.2/i*1actualTlenI22/iII2
5
itoa1operand3i4,ad,1%2/
fprintf1fp1,9Es9,ad2/
8
fprintf1fp1,9:n92/
8
else if1strcmp1opcode,9J>AD92..,2
5
len.strlen1operand2/
itoa1atoi1operand2,a,1,2/
fprintf1fp1,9Ed:tEs:tEs:tEs:t,,,,,Es:n9,address,label,opcode,operand,a2/
8
else if11strcmp1opcode,9AES=92..,21strcmp1opcode,9AESJ92..,22
5
fprintf1fp1,9Ed:tEs:tEs:tEs:n9,address,label,opcode,operand2/
8
else
5
rewind1fp2/
fscanf1fp,9EsEd9,mnemonic,Fcode2/
while1strcmp1opcode,mnemonic2M.,2
fscanf1fp,9EsEd9,mnemonic,Fcode2/
if1strcmp1operand,96692..,2
5
fprintf1fp1,9Ed:tEs:tEs:tEs:tEd,,,,:n9,address,label,opcode,operand,code2/
8
else
5
rewind1fp22/
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
fscanf1fp2,9EsEd9,symbol,Fadd2/
while1strcmp1operand,symbol2M.,2
5
fscanf1fp2,9EsEd9,symbol,Fadd2/
8
fprintf1fp1,9Ed:tEs:tEs:tEs:tEdEd:n9,address,label,opcode,operand,code,add2/
8
8
fscanf1fp3,9EdEsEsEs9,Faddress,label,opcode,operand2/
8
fprintf1fp1,9Ed:tEs:tEs:tEs:n9,address,label,opcode,operand2/
printf19Cinished92/
fclose1fp12/
fclose1fp22/
fclose1fp32/
fclose1fp2/
getch12/
8
INPUT FILES
INTERME5IATE.5AT
66 ST?AT 2,,,
2,,, 66 &D? C!PE
2,,3 66 ST? ?&@B?
2,,% 66 &DCB CB?AQ
2,,O 66 STCB C1
2,12 ?&@B? AESJ 1
2,1$ C!PE J>AD $
2,1N CB?AQ =;TE CUE>CU
2,1O C1 AES= 1
2,2, 66 E'D 66
>@T?=.D?T
&D? 33
ST?
&DCB $3
STCB $(
E'D 6
S;<T?=.D?T
?&@B? 2,12
C!PE 2,1$
CB?AQ 2,1N
C1 2,1O
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
>ST@ST C!&E D
?SS<&!ST.D?T
66 ST?AT 2,,,
2,,, 66 &D? C!PE 332,1$
2,,3 66 ST? ?&@B? 2,12
2,,% 66 &DCB CB?AQ $32,1N
2,,O 66 STCB C1 $(2,1O
2,12 ?&@B? AESJ 1
2,1$ C!PE J>AD $ ,,,,,$
2,1N CB?AQ =;TE CUE>CU $f%
2,1O C1 AES= 1
2,2, 66 E'D 66
RESULT)
Thus pass two of a two pass assembler was implemented in -4

w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
EXPT NO "
I$-1$n% ( sing1 -(ss (ss$)1#4
AIM
To implement a single pass assembler.
ALGORIT2M
S,urce c,de pr,+ram -/ c60-/+*e pa00 a00em1*er
)include*stdio.h+
)include*conio.h+
)include*string.h+
)include*stdlib.h+
struct st
5
char op32$4/
int nb/
char code334/
8s/
0oid main12
5
int i.,,lc,h.,/
char g31,4,c31,4/
C!&E 6fp1,6fp2,6fp3/
clrscr12/
fp1.fopen19pgm.dat9,9r92/
fp3.fopen19oneoutput.dat9,9w92/
fprintf1fp3,9lc:topcode:tobVcode:n92/
lc.,72,,,/
while1Mfeof1fp122
5
fgets1g,3$,fp12/
while1g3i4M.U:nU2
5
if1g3i4+.U?U FF g3i4*.UQU2
5
c3h4.g3i4/
hII/
8
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
iII/
8
c3h4.U:,U/
fp2.fopen19opcode.dat9,9r92/
while1Mfeof1fp222
5
fscanf1fp2,9EsEdEs9,s.op,Fs.nb,s.code2/
if1strcmp1c,s.op2..,2
5
fprintf1fp3,9E7:tEs9,lc2/
switch1s.nb2
5
case 1D
fprintf1fp3,9:tEs:n9,s.code2/
breaG/
case 2D
fprintf1fp3,9:tEs:tEcEc9,s.code,g3iH24,g3iH142/
fprintf1fp3,9:n92/
breaG/
case 3D
fprintf1fp3,9:tEs:tEcEc:tEcEc9,s.code,g3iH24,g3iH14,g3iH4,g3iH342/
fprintf1fp3,9:n92/
breaG/
8
lc.lcIs.nb/
breaG/
8
8
fclose1fp22/
i.,/
h.,/
88
INPUT FILES)
,pc,de.dat
MO7AB 1 %&
A55B 1 &1
M7IA "
STA ! !
2LT 1 %$
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
p+m.dat
M7I A,($
A55 B
STA #((
2LT
RESULT)
Thus a single pass assembler was implemented in C.
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
EXPT NO #
I$-1$n% ( %2' -(ss $(*#' -#'*ss'#
AIM)
To Implement a two pass macro processor
ALGORIT2M)
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
S,urce c,de pr,+ram -/ c6 two pass ma$%o p%o$esso%
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<dos.h>
//------------------------------------------Header Files
struct mnt
{
char name[20];
int mdtinde;
int !"ipFla#;
$mnt[%0];
//-------------------------
struct mdt
{
int srno;
char inst[20];
$mdt[%0];
//-------------------------
struct ala
{
int inde;
char ar#[20];
$ala[%0];
//-------------------------
int mntc&mdtc&alac;
//-----------------------------------------------------
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
char 'replace(str)char 'str& char 'ori#& char 'rep*
{
static char +u,,er[-0./];
char 'p;
if)0)p 1 strstr)str& ori#*** // 2s 3ori#3 e4en in 3str35
{
return str;
$
strncpy)+u,,er& str& p-str*; // 6opy characters ,rom 3str3 start to
3ori#3 st7
+u,,er[p-str] 1 3803;
sprint,)+u,,er9)p-str*&:;s;s:&rep&p9strlen)ori#**;
if)0)p 1 strstr)+u,,er& ori#*** // 2s 3ori#3 e4en in 3+u,,er35
return +u,,er;
else
replace(str)+u,,er&ori#&rep*;
$
//--------------------------------------------------------------
void disp<=<)*
{
int i;
print,):8n2nde8t<r#ument:*;
print,):8n------------------:*;
for)i10;i<alac;i99*
print,):8n ;d ;s:&ala[i].inde&ala[i].ar#*;
$
//---------------------------------------------------------------
void disp>?@)*
{
int i;
print,):8n2nde8t<r#ument:*;
print,):8n------------------:*;
for)i10;i<mdtc;i99*
print,):8n ;d ;s:&mdt[i].srno&mdt[i].inst*;
$
//---------------------------------------------------------------
void pass%)*
{
char ch&ch%;
int ,la#1%;
int i10&A10&"10&l10;
char to"en[%0]&to"en%[%0];
char temp[B]&temp%[B];
char tline[C0]&line[C0];
F2=D 'src;
F2=D 'dest;
clrscr)*;
strcpy)temp&:#:*;
src 1 ,open):ip.c:&:r:*;
dest 1 ,open):op.c:&:E:*;
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
do{
do{ //----> @o !eperate Fut @o"en
ch 1 ,#etc)src*; //----> ch G 6urrent Hointer
to"en[i] 1 ch;
i99;
$while)ch01DFF II 0isspace)ch**;
to"en[i-%] 1 3803; //----> >as" 6urrent ch
//--------------------------------------------
//--------------------------------------------
//--------------------------------------------
if)0strcmp)to"en&:macro:** //--> 6hec" For :macro:
{
do{ //--> >acro Jame
ch% 1 ,#etc)src*;
to"en%[A] 1 ch%;
A99;
$while)ch%01DFF II 0isspace)ch%**;
to"en%[A-%] 1 3803;
//-----------------------------------
strcpy)mnt[mntc].name&to"en%*;
mnt[mntc].mdtinde 1 mdtc;
mntc99;
//-------------------------------------
//2, no Harameter i.e <=< is Dmpty
//-------------------------------------
if)ch%1138n3*
{
mnt[mntc-%].!"ipFla# 1 %;
#oto >id;
$
//-------------------------------------
//6reate <=<
//-------------------------------------
do{ //<=< 6ontent
ch% 1 ,#etc)src*;
if)ch%113I3*
,la#1%;
if)ch%113&3KKch%1138n3*
{
to"en%["]13803;
,la#10;
ala[alac].inde 1 alac;
strcpy)ala[alac].ar#&to"en%*;
alac99;
"10;
$
if),la#11%*
to"en%["99] 1 ch%;
$while)ch%01DFF II ch%0138n3*;
//-----------------------------------------
>idG
,la#1%;
A10;
do
{
line[0]13803;
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
do{ //>?@
ch% 1 ,#etc)src*;
line[A99]1ch%;
$
while)ch%01DFF II ch%0138n3*;
line[A-%]13803;
for)l 1 0 ;l<alac;l99*
{
sprint,)temp%&:;d:&l*; //0
strcat)temp&temp%*; //#0
sprint,)tline&:;s:&replace(str)line&ala[l].ar#&temp**;
// i,)strcmp)tline&::**
strcpy)line&tline*;
strcpy)temp&:#:*;
$
strcpy)mdt[mdtc].inst&line*;
mdt[mdtc].srno 1 mdtc;
mdtc99;
A10;
$while)strcmp)line&:mend:**;
ch 1 3 3;
$//end i,
else
,print,)dest&:;s:&to"en*;
//---------------------------------------------------------------
if)ch1138n3*
,print,)dest&:8n:*;
if)ch113 3*
,print,)dest&: :*;
//----------------------------------------------------------------
if)isspace)ch**
{
to"en[0]13803;
i10;
$
else
{
to"en[0]1 ch;
to"en[%]1 3803;
i1%;
$
$while)ch01DFF*; //Futer od
,close)src*;
,close)dest*;
$
//----------------------------------------------------------------
void disp)*
{
int i;
char ch;
F2=D 'src;
src 1 ,open):op.c:&:r:*;
do{
ch 1 ,#etc)src*;
print,):;c:&ch*;
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
$while)ch01DFF*;
$
//----------------------------------------------------------------
void pass2)*
{
char ch;
int counter10;
int start(inde;
char ch%&ch2&pch; //comment 4alidation
int len&,la#10&s,la#10;
int i 1 0&A10&"10&l10;
char to"en[%0];
char to"en%[%0];
char temp[B]&temp%[B];
char tline[C0];
char line[C0];
char repl[%0];
F2=D 'src;
alac 1 0;
strcpy)temp&:#:*;
src 1 ,open):op.c:&:r:*;
do
{
do{ //For !eperate @o"en
ch 1 ,#etc)src*;
to"en[i] 1 ch;
i99;
$while)ch01DFF II 0isspace)ch**;
to"en[i-%] 1 3803;
//--------------------------------------------
for)A10;A<mntc;A99*
if)0strcmp)to"en&mnt[A].name** //i, to"en1:mac%:
{
s,la# 1 %;
start(inde 1 mnt[A].mdtinde;
if)mnt[A].!"ipFla#11%*
#oto Jet;
do{ //>odi,y <=< 6ontent
ch% 1 ,#etc)src*;
,la#1%;
if)ch%113&3KKch%1138n3*
{
to"en%["]13803;
,la#10;
ala[alac].inde 1 alac;
strcpy)ala[alac].ar#&to"en%*;
alac99;
"10;
counter99;
$
if),la#11%*
to"en%["99] 1 ch%;
$while)ch%01DFF II ch%0138n3*;
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
//-----------------------------------------
JetG
" 1 counter;
do
{
strcpy)line&mdt[start(inde].inst*;
if)0strcmp)line&:mend:**
break;
for)l10;l<";l99*
{
strcpy)temp&:#:*;
sprint,)temp%&:;d:&l*; //temp% 1 :0:
strcat)temp&temp%*; //temp 1 :#: +e,ore noE temp 1 :#0:
strcpy)repl&ala[l].ar#*; //repl 1 %0
sprint,)tline&:;s:&replace(str)line&temp&repl**;
if)strcmp)tline&::**
strcpy)line&tline*;
$
print,):8n;s:&line*;
start(inde99;
$while)strcmp)line&:mend:**;
print,):8n:*;
s,la# 1 %;
$//end i,
if)s,la#110*
{
print,):;s:&to"en*;
$
if)ch1138n3*
print,):8n:*;
if)ch113 3*
print,): :*;
if)isspace)ch**
{
to"en[0]13803;
i10;
$
else
{
to"en[0]1 ch;
to"en[%]1 3803;
i1%;
$
s,la# 1 0;
counter 1 0;
alac 1 0;
to"en%[0] 1 3803;
" 1 0;
$while)ch01DFF*;
,close)src*;
$
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
//-----------------------------------
void main)*
{
clrscr)*;
pass%)*;
print,):8n---------------------------:*;
print,):8n2nput Hro#ram G :*;
print,):8n---------------------------8n:*;
disp)*;
print,):8n---------------------------:*;
print,):8n6ontent o, <=< G :*;
print,):8n---------------------------8n:*;
disp<=<)*;
print,):8n---------------------------:*;
print,):8n6ontent o, >?@ G :*;
print,):8n---------------------------8n:*;
disp>?@)*;
print,):8n----------------------------8n:*;
pass2)*;
#etch)*;
$
RESULT)
Thus a two pass macroprocessor was implemented in C
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
EXPT NO $
I$-1$n% ( sing1 -(ss $(*#' -#'*ss'#4
AIM
To implement a single pass macro processor4
ALGORIT2M
1.Start the macro processor program
2. !nclude the necessary header files and 0ariable
3. >pen the three files
f1.macin.dat with read pri0ilege
f2.macout.dat with write pri0ilege
f3. deftab.dat with write pri0ilege
. Wet the 0ariable form f1 file macin.dat for label,opcode,operand
$. Aead the 0ariable until the opcode is not is eLual to -ero
Then checG if the opcode is eLual to <acro if <acro
Then
%. Copy macroname.label
(. Wet the 0ariable label ,opcode ,operand
N. !n these if condition perform the while loop until opcode is not eLual to <E'D
O. Copy the 0ariable
d3lines4.lab.label
d3lines4.opc.opcode
d3lines4.oper.operand
and increase linesII/
close while loop and if condtion
else if opcode is eLual to macro name
1,. @erform the for loop from , to length
fprint for d3i4.lab,d3i4.opc,d3i4.oper
else if it is not match
fprintf1f2,9Es:tEs:tEs:n9,label,opcode,operand2/
11. Cinally terminate the program
S,urce c,de -/ c pr,+ram 3,r per3,rm S-mp*e macr, pr,ce00,r
) include *stdio.h+
) include *conio.h+
) include *string.h+
) include *stdlib.h+
struct deftab
5
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
char lab31,4/
char opc31,4/
char oper31,4/
8d31,4/
0oid main12
5
char label31,4,opcode31,4,operand31,4,newlabel31,4,newoperand31,4/
char macroname31,4/
int i,lines/
C!&E 6f1,6f2,6f3/
clrscr12/
f1.fopen19macin.dat9,9r92/
f2.fopen19macout.dat9,9w92/
f3.fopen19deftab.dat9,9w92/
fscanf1f1,9EsEsEs9,label,opcode,operand2/
while1strcmp1opcode,9E'D92M.,2
5
if1strcmp1opcode,9<?CA>92..,2
5
strcpy1macroname,label2/
fscanf1f1,9EsEsEs9,label,opcode,operand2/
lines.,/
while1strcmp1opcode,9<E'D92M.,2
5
fprintf1f3,9Es:tEs:tEs:n9,label,opcode,operand2/
strcpy1d3lines4.lab,label2/
strcpy1d3lines4.opc,opcode2/
strcpy1d3lines4.oper,operand2/
fscanf1f1,9EsEsEs9,label,opcode,operand2/
linesII/
8
8
else if1strcmp1opcode,macroname2..,2
5
printf19&ines . Ed:n9,lines2/
for1i.,/i*lines/iII2
5
fprintf1f2,9Es:tEs:tEs:n9,d3i4.lab,d3i4.opc,d3i4.oper2/
printf19D&?= . Es:nD>@C . Es:nD>@EA . Es:n9,d3i4.lab,d3i4.opc,d3i4.oper2/
8
8
else
fprintf1f2,9Es:tEs:tEs:n9,label,opcode,operand2/
fscanf1f1,9EsEsEs9,label,opcode,operand2/
8
fprintf1f2,9Es:tEs:tEs:n9,label,opcode,operand2/
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
fclose1f12/
fclose1f22/
fclose1f32/
printf19C!'!SBED92/
getch12/
8
!'@ST C!&E D
<?C!'.D?T
C?&C ST?AT 1,,,
SS< <?CA> 66
66 &D? )$
66 ?DD )1,
66 ST? 2,,,
66 <E'D 66
66 &D? &E'WTB
66 C><@ QEA>
66 XEY &>>@
66 SS< 66
&E'WTB J>AD $
QEA> J>AD ,
&>>@ SS< 66
66 E'D 66
>ST@ST C!&ES D
<?C>ST.D?T
C?&C ST?AT 1,,,
66 &D? &E'WTB
66 C><@ QEA>
66 XEY &>>@
66 &D? )$
66 ?DD )1,
66 ST? 2,,,
&E'WTB J>AD $
QEA> J>AD ,
66 &D? )$
66 ?DD )1,
66 ST? 2,,,
66 E'D 66
DECT?=.D?T
66 &D? )$
66 ?DD )1,
66 ST? 2,,,
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
RESULT)
Thus a single pass macroprocessor was implemented in C.
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
EXPT NO %
I$-1$n% (n ()s'1"% 1'(,#4
AIM)
To implement an absolute loader.
ALGORIT2M)
1. Start the program
2. ?ssign the reLuired 0ariable
3. >pen the files
fp1.fopen19input.dat9,9r92/
fp2.fopen19output.dat9,9w92/
. Aead the content
$. Ssing while loop perform the loop until character is not eLual to E
4.-*e80trcmp8-/put,9E9:;<(:
Then compare the character is eLual to B
I3 2 t.e/
fscanf1fp1,9Ed9,Fstart2/
&iGe that get length, and input
Else if the character is T
Then
Then perform the frprintf in fp1 for input file for ,
input3,4,inuput314 for address
input324,inuput334 for addressI1
input34,inuput3$4 for addressI2
Else if it is not B or T
Then perform the frprintf in fp2 for output file for ,
input3,4,inuput314 for address
input324,inuput334 for addressI1
input34,inuput3$4 for addressI2
fprintf1fp2,9Ed:tEcEc:n9,address,input3,4,input3142/
fprintf1fp2,9Ed:tEcEc:n9,1addressI12,input324,input3342/
fprintf1fp2,9Ed:tEcEc:n9,1addressI22,input34,input3$42/
addressI.3/
fscanf1fp1,9Es9,input2/
%. Cinally terminate the program
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
S,urce c,de pr,+ram -/ c per3,rm-/+ A10,*uter L,ader
) include *stdio.h+
) include *conio.h+
) include *string.h+
0oid main12
5
char input31,4/
int start,length,address/
C!&E 6fp1,6fp2/
clrscr12/
fp1.fopen19input.dat9,9r92/
fp2.fopen19output.dat9,9w92/
fscanf1fp1,9Es9,input2/
while1strcmp1input,9E92M.,2
5
if1strcmp1input,9B92..,2
5
fscanf1fp1,9Ed9,Fstart2/
fscanf1fp1,9Ed9,Flength2/
fscanf1fp1,9Es9,input2/
8
else if1strcmp1input,9T92..,2
5
fscanf1fp1,9Ed9,Faddress2/
fscanf1fp1,9Es9,input2/
fprintf1fp2,9Ed:tEcEc:n9,address,input3,4,input3142/
fprintf1fp2,9Ed:tEcEc:n9,1addressI12,input324,input3342/
fprintf1fp2,9Ed:tEcEc:n9,1addressI22,input34,input3$42/
addressI.3/
fscanf1fp1,9Es9,input2/
8
else
5
fprintf1fp2,9Ed:tEcEc:n9,address,input3,4,input3142/
fprintf1fp2,9Ed:tEcEc:n9,1addressI12,input324,input3342/
fprintf1fp2,9Ed:tEcEc:n9,1addressI22,input34,input3$42/
addressI.3/
fscanf1fp1,9Es9,input2/
8
8
fclose1fp12/
fclose1fp22/
printf19C!'!SBED92/
getch12/
8
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
!'@ST C!&E
!'@ST.D?T
B 1,,, 232
T 1,,, 12,33 N3,3O 1,2,3%
T 2,,, 2ON3,, 23,,,, 2N2,3, 3,2,1$
E
OUTPUT FILE
>ST@ST.D?T
1,,, 1
1,,1 2,
1,,2 33
1,,3 N
1,, 3,
1,,$ 3O
1,,% 1,
1,,( 2,
1,,N 3%
2,,, 2O
2,,1 N3
2,,2 ,,
2,,3 23
2,, ,,
2,,$ ,,
2,,% 2N
2,,( 2,
2,,N 3,
2,,O 3,
2,1, 2,
2,11 1$

RESULT)
Thus an absolute loader was implemented in C.
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
EXPT NO &
I$-1$n% ( #1'*(%ing 1'(,#4
AIM
To implement a relocating loader.
ALGORIT2M
1. Start the program
2. !nclude the necessary header file and 0ariable
3. >pen the two file for
fp1. relinput.dat and gi0e read
fp2. reloutput.dat and gi0e write
. Aead the content
$. Ssing while loop perform the loop until character is not eLual to E
4.-*e80trcmp8-/put,9E9:;<(:
!f the character is B
Wet the 0ariable add, length, and input
Else if the character is T
Wet the 0ariable address and bitmasG
?nd perform the for loop for starting -ero to up to len
Wet the opcode ,addr and assign relocbit to bitmasG
!f relocabit is -ero
T.e/
actualadd.addr/
e*0e
?dd the addr and star 0alue
%. Cinally terminate the program
S,urce c,de pr,+ram -/ c 3,r Re*,cat-,/ L,ader
) include *stdio.h+
) include *conio.h+
) include *string.h+
) include *stdlib.h+
0oid main12
5
char add3%4,length31,4,input31,4,binary3124,bitmasG3124,relocbit/
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
int start,inp,len,i,address,opcode,addr,actualadd/
C!&E 6fp1,6fp2/
clrscr12/
printf19Enter the actual starting address D 92/
scanf19Ed9,Fstart2/
fp1.fopen19relinput.dat9,9r92/
fp2.fopen19reloutput.dat9,9w92/
fscanf1fp1,9Es9,input2/
while1strcmp1input,9E92M.,2
5
if1strcmp1input,9B92..,2
5
fscanf1fp1,9Es9,add2/
fscanf1fp1,9Es9,length2/
fscanf1fp1,9Es9,input2/
8
if1strcmp1input,9T92..,2
5
fscanf1fp1,9Ed9,Faddress2/
fscanf1fp1,9Es9,bitmasG2/
addressI.start/
len.strlen1bitmasG2/
for1i.,/i*len/iII2
5
fscanf1fp1,9Ed9,Fopcode2/
fscanf1fp1,9Ed9,Faddr2/
relocbit.bitmasG3i4/
if1relocbit..U,U2
actualadd.addr/
else
actualadd.addrIstart/
fprintf1fp2,9Ed:tEdEd:n9,address,opcode,actualadd2/
addressI.3/
8
fscanf1fp1,9Es9,input2/
8
8
fclose1fp12/
fclose1fp22/
printf19C!'!SBED92/
getch12/
8
!'@ST D AE&!'@ST.D?T
B 1,,, 2,,
T 1,,, 11,,1 1 1,33 N 1,3O O, 1((% O2 1(%$ $( 1(%$
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
T 2,11 1111, 23 1N3N 3 1O(O NO 1,%, %% 1NO OO 1((
E 1,,,
>ST@ST D
Enter the actual starting address D,,,
AE&>ST@ST.D?T
,,, 1,33
,,3 N,3O
,,% O,1((%
,,O O21(%$
,12 $((%$
$,11 23N3N
$,1 3O(O
$,1( NO,%,
$,2, %%NO
$,23 OO1((
AESS&TD
Thus a relocating loader was implemented in C.

w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
EXPT NO '
I$-1$n% -(ss 'n '& ( ,i#*%.1in5ing 1'(,#4
AIM
To implement pass one of a direct"lin#ing loader.
OB=ECTI7ES
1. Start the program for linGing loader
2. ?ssign the necessary 0ariable and the header 0ariable
3. >pen the two file
. !n fp1 for linG input file for read pri0ilege
$. ?nd fp2 for load map file for write pri0ilege
%. Aead the character until the input is not eLual to E'D
(. ?nd the checG the character in if condition input is B then
N. Wet the name from fp1
O. Copy the name between csname.name
1,. ?nd e7tsym.66
11. Else if the character is D
12. Then get the input 0ariable
13. !n these if condition perform the while loop the read character until the input
is not eLual to A
The copy csnmae.66
1. ?nd e7tsym.input
1$. Then add address .addIcsaddr
1%. ?nd length is eLual to -ero
1(. ?nd perform the operation 1see the Source code2
1N. Cinally terminate the program
S,urce c,de -/ c pr,+ram per3,rm-/+ pa00e0 ,/e *-/>-/+ *,ader
) include *stdio.h+
) include *conio.h+
) include *string.h+
) define <?Z 2,
struct estab
5
char csname31,4/
char e7tsym31,4/
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
int address/
int length/
8es3<?Z4/
0oid main12
5
char input31,4,name31,4,symbol31,4/
int count.,,progaddr,csaddr,add,len/
C!&E 6fp1,6fp2/
clrscr12/
fp1.fopen19linGinput.dat9,9r92/
fp2.fopen19loadmap.dat9,9w92/
printf19Enter the location where the program has to be loaded D 92/
scanf19Ed9,Fprogaddr2/
csaddr.progaddr/
fprintf1fp2,9CST'?<E:tEZTTS;<T'?<E:t?DDAESS:t&E'WTB:n92/
fprintf1fp2,9HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH:n92/
fscanf1fp1,9Es9,input2/
while1strcmp1input,9E'D92M.,2
5
if1strcmp1input,9B92..,2
5
fscanf1fp1,9Es9,name2/
strcpy1es3count4.csname,name2/
strcpy1es3count4.e7tsym,96692/
fscanf1fp1,9Ed9,Fadd2/
es3count4.address.addIcsaddr/
fscanf1fp1,9Ed9,Flen2/
es3count4.length.len/
fprintf1fp2,9Es:tEs:t:tEd:t
Ed:n9,es3count4.csname,es3count4.e7tsym,es3count4.address,es3count4.length2/
countII/
8
else if1strcmp1input,9D92..,2
5
fscanf1fp1,9Es9,input2/
while1strcmp1input,9A92M.,2
5
strcpy1es3count4.csname,96692/
strcpy1es3count4.e7tsym,input2/
fscanf1fp1,9Ed9,Fadd2/
[[ printf19CS?DDA . Ed9,csaddr2/
es3count4.address.addIcsaddr/
es3count4.length.,/
fprintf1fp2,9Es:tEs:t:tEd:t
Ed:n9,es3count4.csname,es3count4.e7tsym,es3count4.address,es3count4.length2/
countII/
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
fscanf1fp1,9Es9,input2/
8
csaddr.csaddrIlen/
8
else if1strcmp1input,9T92..,2
5
while1strcmp1input,9E92M.,2
fscanf1fp1,9Es9,input2/
8
fscanf1fp1,9Es9,input2/
8
fprintf1fp2,9HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH:n92/
fclose1fp12/
fclose1fp22/
printf19C!'!SBED:n92/
getch12/
8
!'@ST C!&E D
&!'\!'@ST.D?T
B @A>W? ,,,, 1,,,
D &!ST? ,,, E'D? ,,$
A &!ST= E'D= &!STC E'DC
T ,,2, 11,33 %$$$$ %(NO,O $%N(N( 3$%(N
T ,,$ ,,,,1 (NO,N( ((%$$$ N(%%%% $%%%%
< ,,$ ,% I&!STC
E ,,,,
B @A>W= ,,,, 2,,,
D &!ST= ,,, E'D= ,,$
A &!ST? E'D? &!STC E'DC
T ,,2, 11,33 %$$$$ %(NO,O $%N(N( 3$%(N
T ,,$ ,,,,,, (NO,N( ((%$$$ N(%%%% $%%%%
< ,,$ ,% IE'D?
< ,,$ ,% H&!ST?
< ,,$ ,% I&!STC
E ,,,,
B @A>WC ,,,, 3,,,
D &!STC ,,, E'DC ,,$
A &!ST? E'D? &!STC E'D=
T ,,2, 11,33 %$$$$ %(NO,O $%N(N( 3$%(N
T ,,$ ,,,,2, (NO,N( ((%$$$ N(%%%% $%%%%
< ,,$ ,% IE'D?
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
< ,,$ ,% H&!ST?
< ,,$ ,% I@A>WC
E ,,,,
E'D
OUTPUT)
Enter the location where the program has to be loaded D $,,,
&>?D<?@.D?T
CST'?<E EZTTS;<T'?<E ?DDAESS &E'WTB
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
@A>W? 66 $,,, 1,,,
66 &!ST? $,, ,
66 E'D? $,$ ,
@A>W= 66 %,,, 2,,,
66 &!ST= %,, ,
66 E'D= %,$ ,
@A>WC 66 N,,, 3,,,
66 &!STC N,, ,
66 E'DC N,$ ,
AESS&TD
Thus pass one of a direct linGing loader was implemented in C.

w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
EXPT NO 1(
I$-1$n% -(ss %2' '& ( ,i#*%.1in5ing 1'(,#4
AIM
To implement pass two of a direct"lin#ing loader.
RESULT)
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
EXPT NO 11
I$-1$n% ( si$-1 %6% ,i%'# 2i%+ &(%"#s 1i5 ins#%i'n 7 ,1%i'n
'& ( *+(#(*%#3 2'#,3 (n, sn%n*4
AIM
To implement a simple te%t editor with features li#e insertion & deletion of a
character, word, and sentence.
ALGORIT2M
S,urce c,de -/ c Pr,+ram 3,r Te?t Ed-t,r
) include *stdio.h+
) include *conio.h+
) include *ctype.h+
) include *dos.h+
) include *iostream.h+
) include *fstream.h+
char filename31$4/
char buff31,,,4/
int cur7,cury,count/
0oid curTpos12
5
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
cur7.where712/
cury.wherey12/
te7tcolor1122/
te7tbacGground1O2/
goto7y13$,12/
cout**9:n9/
cout**9)))))))))))))))))))))))))))))))))))))))))))))):n9/
cout**9:n9/
cout**9:t:tTEZT ED!T>A:n9/
cout**9)))))))))))))))))))))))))))))))))))))))))))))):n9/
cout**9:n Type your te7t and then press ESC Gey:n9/
goto7y11,,,$,,2/
cprintf19E2dE2d9,cury,cur72/
goto7y1cur7,cury2/
8
0oid main12
5
char ch,c/
ofstream outfile/
ifstream infile/
clrscr12/
curTpos12/
cur7.where712/
cury.wherey12/
while1cM.2(2
5
c.getch12/
switch1c2
5
case N,D [[down arrow
goto7y1cur7,curyI12/
breaG/
case ((D [[right side
goto7y1cur7I1,cury2/
breaG/
case (2D [[up arrow
goto7y1cur7,curyH12/
breaG/
case ($D [[left side
goto7y1cur7H1,cury2/
breaG/
case 32D [[space
printf19 92/
buff3countII4.U U/
breaG/
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
case 13D [[new line
goto7y11,curyI12/
buff3countII4.U:nU/
breaG/
defaultD
te7tcolor1132/
if11c+.%$ FF c*.1222 1c+N FF c*$(22
cprintf19Ec9,c2/
breaG/
8
buff3countII4.c/
curTpos12/
8
cprintf19:n:nDo you want to sa0eK 1y[n292/
scanf19Ec9,Fc2/
if11c..UyU21c..U;U22
5
cprintf19:n:nEnter the file name with e7tension in N characters only92/
scanf19Es9,filename2/
outfile.open1filename,iosDDout2/
outfile**buff/
outfile.close12/
cout**9:nDo you want to openK 1y[n2 :n9/
ch.getch12/
if11ch..UyU21ch..U;U22
5
cprintf19:n:nEnter the file name to open92/
scanf19Es9,filename2/
infile.open1filename,iosDDin2/
infile.get1buff,count,U6U2/
goto7y1O,,12/
printf19Es9,buff2/
getch12/
infile.close12/
8
8
8
RESULT)
Thus a Te7t editor was implemented in C
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
EXPT NO 1
I$-1$n% ( s0$)'1 %()1 2i%+ s"i%()1 +(s+ing
AIM
To implement a symbol table with suitable hashing
ALGORIT2M
S,urce c,de -/ c Pr,+ram 3,r Sym1,* ta1*e
) include *stdio.h+
) include *conio.h+
) include *ctype.h+
) include *dos.h+
) include *iostream.h+
) include *fstream.h+
0oid main12
5
int i,V,G,n,add.,,si-e/
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
char c,in32,4,temp32,4,0al32,4,0ar32,4/
C!&E6fp/
clrscr12/
fp.fopen19input.c9,9r92/
c.getc1fp2/
printf1U:n TBE !'@ST C!&E !SD92
while1Mfeof1fp22
5
printf19Ec9,c2/
c.getc1fp2/
8
fclose1fp2/
printf19:n66666666666666symbol table6666666666666692/
printf19:n D?ta type:t'ame:t'o.of Elements:tSi-e:t?ddress92/
printf1966666666666666666666666666666666666692/
while1Mfeof1fp22
5
if1isalpha1c22
5
i.,/
do
5
temp3i..4.c
c.getc1fp2/
8while1isalpha1c22/
temp3i4.U:,U/
if1strcmp19int9,temp2..,2
5
strcpy10al,9 92/
strcpy1in,9 92/
strcpy10ar,9 92/
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
while1cM.U/U2
5
strcpy10al,9 92/
c.getc1fp2/
i.,/
do
5
0ar3iII4.c/
c.getc1fp2/
8while1isalpha1c22/
0ar3i4.U:,U/
if1c..U3U2
5
i.,/
c.getc1fp2/
strcpy1in,9 92
do
5
in3iII4.c/
c.getc1fp2/
G.atoi1in2/
si-e.si-e6G/
8
else
5
strcpy1in,U1U2/
si-e.2/
8
if1c..U.U2
c.getc1fp2/
i.,/
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
do
5
0al3iII4.c/
c.getc1fp2/
8while1cM.U,UFFcM.U/U2
0al3i4.U:,U/
8
printf19:nEs:t:tEs:tEs:t:tEs:tEd=ytes:tEd9,temp,0ar,0al,in,si-e,add2/
add.addIsi-e/
8
8
8
else
c.getc1fp2/
8
getch12/
8
RESULT)
T.u0 t.e 0ym1,* ta1*e 4a0 +e/erated u0-/+ C.
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
VIVA VOCE QUESTIONS WITH ANSWERS
INTRODUCTION
1. Define system software.
It consists of variety of programs that supports the operation of the
computer. This
software makes it possible for the user to focus on the other problems to
be solved with out
needing to know how the machine works internally.
Eg: operating system, assembler, loader.
2. i!e some a""#i$ations of o"eratin% system.
to make the computer easier to use
to manage the resources in computer
process management
data and memory management
to provide security to the user.
Operating system acts as an interface between the user and the system
Eg:windows,linux,unix,dos
&. Define $om"i#er an' inter"reter.
ompiler is a set of program which converts the whole high level
language program
to machine language program.
Interpreter is a set of programs which converts high level language
program to machine
language program line by line.
(. Define #oa'er.
!oader is a set of program that loads the machine language translated by
the translator
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
into the main memory and makes it ready for execution.
). W*at is t*e nee' of +AR re%ister,
"#$ %memory address register& is used to store the address of the
memory from which
the data is to be read or to which the data is to be written.
-. Draw SS instr.$tion format.
opcode ! '( )( '* )*
+ , - (. (/ (0 *+ 1( 1* 1. 1/ 2,
It is a / byte instruction used to move !3I bytes data fro the storage
location( to the
storage location*.
4torage location( 5 )(36'(7
4torage location* 5 )*36'*7
*+
Eg: "O8 /+,2++%1&,.++%2&
/. i!e any two 'ifferen$es 0etween 0ase re#ati!e a''ressin% an'
"ro%ram $o.nter
re#ati!e a''ressin% .se' in SIC12E.
3. Define in'ire$t a''ressin%
In the case of immediate addressing the operand field gives the memory
location. The
word from the given address is fetched and it gives the address of the
operand.
Eg:#)) $., 6/++7
9ere the second operand is given in indirect addressing mode. :irst the
word in
memory location /++ is fetched and which will give the address of the
operand.
4. Define imme'iate a''ressin%.
In this addressing mode the operand value is given directly. There is no
need to refer
memory. The immediate addressing is indicated by the prefix ;<=.
Eg: #)) <.
In this instruction one operand is in accumulator and the second operand
is an
immediate value the value . is directly added with the accumulator
content and the result is
stored in accumulator.
15. 6ist o.t any two CISC an' RISC ma$*ine.
I4 >?ower ?, ray T1E
$I4 > 8#@,?entium ?ro architecture
11. 7o##owin% is a memory $onfi%.ration8
A''ress Va#.e Re%ister R
1 ) )
) /
- )
W*at is t*e res.#t of t*e fo##owin% statement,
9ase re#ati!e a''ressin% ? relative addressing
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
9ere the Target address is calculated
using the formula
Target address 5 )isplacement 3 6'7
'Abase register
9ere the target address is calculated using the
formula
Target address 5 )isplacement 3 6?7
?Aprogram counter
)isplacement lies between + to 2+0. )isplacement lies between >*+2- to
*+2,
*(
ADD -:imme'iate; to R :in'ire$t;
9ere / is the immediate data and the next value is indirect data. ie, the
register contains
the address of the operand. 9ere the address of the operand is . and its
corresponding value
is ,.
/ 3 6$7 5 /3 6.7 5 /3 , 5(1
12. 7o##owin% is a memory $onfi%.ration8
A''ress Va#.e Re%ister R
( 4 -
) /
- 2
W*at is t*e res.#t of t*e fo##owin% statement,
SU9 (:'ire$t; to R :'ire$t;
9ere one operand is in the address location 2%direct addressing& and the
next operand
is in the register %register direct&.
The resultant value is 0 >/ 51.
1&. W*at is t*e name of A an' 6 re%ister in SIC ma$*ine an' a#so
s"e$ify its .se.
#Aaccumulator
Bsed for arithmetic operation. i.e., in the case of arithmetic operations
one operand is
in the accumulator, and other operand may be an immediate value,
register operand or
memory content. The operation given in the instruction is performed and
the result is stored
in the accumulator register.
!Alinkage register
It is used to store the return address in the case of Cump to subroutine
%D4B'&
instructions.
1(. W*at are t*e instr.$tion formats .se' in SIC12E ar$*ite$t.re,
i!e any one
format.
:ormat ( %( byte&, :ormat * %* bytes&, :ormat 1 %1 bytes& E :ormat 2%2
bytes&
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
:ormat *:
- 2 2
O?O)E $( $*
1). Consi'er t*e instr.$tions in SIC1 2E "ro%rammin%
15 1555 6ENTH RESW (
**
25 <<<<< NEW WORD &
W*at is t*e !a#.e assi%n to t*e sym0o# NEW,
In the line (+ the address is (+++ and the instruction is $E4F 2.It
reserves 2
word %1 x 2 5(*& areas for the symbol !EGHT9. hence (* is added to the
!OT$.
Thus the value of the symbol GEF is (+++3(* 5(++.
1-. W*at is t*e 'ifferen$e 0etween t*e instr.$tions 6DA = & an'
6DA THREE,
In the first instruction immediate addressing is used. 9ere the value 1 is
directly
loaded into the accumulator register.
In the second instruction the memory reference is used. 9ere the address
%address
assigned for the symbol T9$EE& is loaded into the accumulator register.
1/. Differentiate trai#in% n.meri$ an' #ea'in% se"arate n.meri$.
The numeric format is used to represent numeric values with one digit per
byte. In the
numeric format if the sign appears in the last byte it is known as the
trailing numeric. If the
sign appears in a separate byte preceding the first digit then it is called as
leading separate
numeric.
13. W*at are t*e a''ressin% mo'es .se' in VA2 ar$*ite$t.re,
$egister directI register deferred, auto increment and decrement,
program counter
relative, base relative, index register mode and indirect addressing are
the various addressing
modes in 8#@ architecture.
14. How 'o yo. $a#$.#ate t*e a$t.a# a''ress in t*e $ase of
re%ister in'ire$t wit*
imme'iate in'e> mo'e,
9ere the target address is calculated using the formula
T.# 5%register& 3 displacement.
25. Write t*e se?.en$e of instr.$tions to "erform t*e o"eration
9ETA @ A6AHA B 1
.sin% SIC instr.$tions.
!)# #!?9#
#)) OGE
4T# 'ET#
J. J.
#!?9# $E4F (
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
'ET# $E4F (
OGE $E4F (
21. Write t*e se?.en$e of instr.$tions to "erform t*e o"eration
9ETA @ A6AHAB)
.sin% SIC12E instr.$tions.
*1
!)# #!?9#
#)) <(
4T# 'ET#
J. J.
#!?9# $E4F (
9ETA RESW 1
22. W*at is t*e .se of TD instr.$tion in SIC ar$*ite$t.re,
The test device %T)& instruction tests whether the addressed device is
ready to send or
receive a byte of data. The condition code is set to indicate the result of
this test. 4etting of K
means the device is ready to send or receive, and 5 means the device is
not ready.
ASSE+96ERS
1. Define t*e 0asi$ f.n$tions of assem0#er.
L Translating mnemonic operation codes to their machine language
eMuivalents.
L #ssigning machine addresses to symbolic labels used by the
programmer.
2. W*at is meant 0y assem0#er 'ire$ti!es, i!e e>am"#e.
These are the statements that are not translated into machine
instructions, but they
provide instructions to assembler itself.
example 4T#$T,EG),'NTE,FO$),$E4F and $E4'.
&. W*at are forwar' referen$es,
It is a reference to a label that is defined later in a program.
onsider the statement
(+ (+++ 4T! $ET#)$
. . . .
. . . .
-+ (+1/ $ET#)$ $E4F (
The first instruction contains a forward reference $ET#)$. If we attempt
to translate
the program line by line, we will unable to process the statement in line(+
because we do not
know the address that will be assigned to $ET#)$ .The address is
assigned later%in line -+&
in the program.
(. W*at are t*e t*ree 'ifferent re$or's .se' in o0Ce$t "ro%ram,
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
The header record, text record and the end record are the three different
records used
in obCect program.
*2
The header record contains the program name, starting address and
length of the
program.
Text record contains the translated instructions and data of the program.
End record marks the end of the obCect program and specifies the address
in the
program where execution is to begin.
). W*at is t*e nee' of SD+TA9 :sym0o# ta0#e; in assem0#er,
The symbol table includes the name and value for each symbol in the
source program,
together with flags to indicate error conditions. 4ome times it may contain
details about the
data area. 4N"T#' is usually organiOed as a hash table for efficiency of
insertion and
retrieval.
-. W*at is t*e nee' of OATA9 :o"eration $o'e ta0#e; in
assem0#er,
The operation code table contains the mnemonic operation code and its
machine
language eMuivalent. 4ome assemblers it may also contain information
about instruction
format and length. O?T#' is usually organiOed as a hash table, with
mnemonic operation
code as the key.
/. W*at are t*e sym0o# 'efinin% statements %enera##y .se' in
assem0#ers,
;EPB=Ait allows the programmer to define symbols and specify their
values
directly. The general format is
4ymbol EQU value
;O$H=Ait is used to indirectly assign values to symbols. Fhen this
statement is
encountered the assembler resets its location counter to the specified
value. The
general format is
OR value
In the above two statements value is a constant or an expression
involving constants
and previously defined symbols.
3. Define re#o$ata0#e "ro%ram.
#n obCect program that contains the information necessary to perform
reMuired
modification in the obCect code depends on the starting location of the
program during load
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
time is known as relocatable program.
4. Differentiate a0so#.te e>"ression an' re#ati!e e>"ression.
If the result of the expression is an absolute value %constant& then it is
known as
absolute expression.
Eg: 'B:EG) > 'B::E$
*.
If the result of the expression is relative to the beginning of the program
then it is
known as relative expression. label on instructions and data areas and
references to the
location counter values are relative terms.
Eg: 'B:EG) 3 'B::E$
15. Write t*e ste"s re?.ire' to trans#ate t*e so.r$e "ro%ram to
o0Ce$t "ro%ram.
onvert mnemonic operation codes to their machine language
eMuivalents.
onvert symbolic operands to their eMuivalent machine addresses
'uild the machine instruction in the proper format.
onvert the data constants specified in the source program into their
internal machine
representation
Frite the obCect program and assembly listing.
11. W*at is t*e .se of t*e !aria0#e 6OCCTR :#o$ation $o.nter; in
assem0#er,
This variable is used to assign addresses to the symbols. !OT$ is
initialiOed to the
beginning address specified in the 4T#$T statement. #fter each source
statement is
processed the length of the assembled instruction or data area to be
generated is added to
!OT$ and hence whenever we reach a label in the source program the
current value of
!OT$ gives the address associated with the label.
12. Define #oa' an' %o assem0#er.
One pass assembler that generates their obCect code in memory for
immediate
execution is known as load and go assembler. 9ere no obCect programmer
is written out and
hence no need for loader.
1&. W*at are t*e two 'ifferent ty"es of C.m" statements .se' in
+AS+ assem0#er,
Gear Cump
# near Cump is a Cump to a target in the same segment and it is
assembled by using a current
code segment 4.
:ar Cump
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
# far Cump is a Cump to a target in a different code segment and it is
assembled by using
different segment registers .
1(. W*at is t*e .se of 0ase re%ister ta0#e in AI2 assem0#er,
# base register table is used to remember which of the general purpose
registers are
currently available as base registers and also the base addresses they
contain.
*/
.B4IGH statement causes entry to the table and .)$O? statement
removes the
corresponding table entry.
1). Differentiate t*e assem0#er 'ire$ti!es RESW an' RES9.
$E4F >It reserves the indicated number of words for data area.
Eg: (+ (++1 T9$EE $E4F (
In this instruction one word area %1 bytes& is reserved for the symbol
T9$EE. If the
memory is byte addressable then the address assigned for the next
symbol is (++/.
$E4' >It reserves the indicated number of bytes for data area.
Eg: (+ (++- IG?BT $E4' (
In this instruction one byte area is reserved for the symbol IG?BT .9ence
the address
assigned for the next symbol is (++0.
1-. Define mo'ifi$ation re$or' an' %i!e its format.
This record contains the information about the modification in the obCect
code during
program relocation. the general format is
ol ( "
ol *A, 4tarting location of the address field to be modified relative to the
beginning
of the program
ol -A0 length of the address field to be modified in half bytes.
1/. Write 'own t*e "ass n.m0ers :AASS 11 AASS 2; of t*e
fo##owin% a$ti!ities t*at o$$.r
in a two "ass assem0#er8
a. O0Ce$t $o'e %eneration
0. 6itera#s a''e' to #itera# ta0#e
$. 6istin% "rinte'
'. A''ress #o$ation of #o$a# sym0o#s
#nswer:
a. ObCect code generation A ?#44 *
b. !iterals added to literal table > ?#44 (
c. !isting printed > ?#44*
d. #ddress location of local symbols > ?#44(
13. W*at is meant 0y ma$*ine in'e"en'ent assem0#er feat.res,
The assembler features that do not depend upon the machine
architecture are known
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
as machine independent assembler features.
*,
Eg: program blocks, !iterals.
14. How t*e re%ister to re%ister instr.$tions are trans#ate' in
assem0#er,
In the case of register to register instructions the operand field contains
the register
name. )uring the translation first the obCect code is converted into its
corresponding machine
language eMuivalent with the help of O?T#'. Then the 4N"T#' is
searched for the
numeric eMuivalent of register and that value is inserted into the operand
field.
Eg: (*. (+1/ $)$E !E#$ @ '2(+
'2Amacine eMuivalent of the opcode !E#$
(+Anumeric eMuivalent of the register @.
25. W*at is meant 0y e>terna# referen$es,
#ssembler program can be divided into many sections known as control
sections and
each control section can be loaded and relocated independently of the
others. If the
instruction in one control section need to refer instruction or data in
another control section
.the assembler is unable to process these references in normal way. 4uch
references between
control are called external references.
21. Define $ontro# se$tion.
# control section is a part of the program that maintains its identity after
assemblyI
each control section can be loaded and relocated independently of the
others.
ontrol sections are most often used for subroutines. The maCor benefit of
using
control sections is to increase flexibility.
22. W*at is t*e 'ifferen$e 0etween t*e assem0#er 'ire$ti!e
E2TRE7 an' E2TDE7.
E@T)E: names external symbols that are defined in a particular control
section
and may be used in other sections.
E@T$E: names external symbols that are referred in a particular control
section and
defined in another control section.
2&. i!e t*e %enera# format of 'efine re$or'.
This record gives information about external symbols that are defined in a
particular
control section. The format is
ol ( )
ol *A, name of external symbol defined in this control section
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
ol -A(1 relative address of the symbol with in this control section
ol (2A,1 name and relative address for other external symbols.
2(. i!e t*e .se of assem0#er 'ire$ti!e CSECT an' USE
*-
4ET A used to divide the program into many control sections
B4E > used to divide the program in to many blocks called program blocks
2). W*at is t*e .se of t*e assem0#er 'ire$ti!e START,
The assembler directive 4T#$T gives the name and starting address of
the program.
The format is
?G 4T#$T (+++
9ere
?G > Game of the program
(+++ A 4tarting address of the program.
6OADERS AND 6INEERS
1. W*at are t*e 0asi$ f.n$tions of #oa'ers,
!oading > brings the obCect program into memory for execution
$elocation > modifies the obCect program so that it can be loaded at an
address
different from the location originally specified
!inking > combines two or more separate obCect programs and also
supplies the
information needed to reference them.
2. Define a0so#.te #oa'er.
The loader, which is used only for loading, is known as absolute loader.
e.g. 'ootstrap loader
&. W*at is meant 0y 0ootstra" #oa'er,
This is a special type of absolute loader which loads the first program to
be run by the
computer. %usually an operating system&
(. W*at are re#ati!e :re#o$ati!e; #oa'ers,
!oaders that allow for program relocation are called relocating
%relocative& loaders.
). W*at is t*e .se of mo'ifi$ation re$or',
"odification record is used for program relocation. Each modification
record
specifies the starting address and the length of the field whose value is to
be altered and also
describes the modification to be performed.
-. W*at are t*e 2 'ifferent te$*ni?.es .se' for re#o$ation,
*0
"odification record method and relocation bit method.
/. Define Re#o$ation 0it met*o'.
If the relocation bit corresponding to a word of obCect code is set to (, the
program=s
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
starting address is to be added to this word when the program is
relocated. 'it value +
indicates no modification is reMuired.
3. Define 0it masF.
The relocation bits are gathered together following the length indicator in
each text
record and which is called as bit mask. :or e.g. the bit mask
::%((((((((((++& specifies
that the first (+ words of obCect code are to be modified during relocation.
4. W*at is t*e nee' of ESTA9,
It is used to store the name and address of the each external symbol. It
also indicates
in which control section the symbol is defined.
15. W*at is t*e .se of t*e !aria0#e AROADDR,
It gives the beginning address in memory where the linked program is to
be loaded.
The starting address is obtained from the operating system.
11. Write t*e two "asses of a #inFin% #oa'er.
?ass(: assigns address to all external symbols
?ass*: it performs actual loading, relocation and linking.
12. Define a.tomati$ #i0rary sear$*.
In many linking loaders the subroutines called by the program being
loaded are
automatically fetched from the library, linked with the main program and
loaded. This feature
is referred to as automatic library search.
1&. 6ist t*e #oa'er o"tions INC6UDE GDE6ETE.
The general format of IG!B)E is
IG!B)E programQname %library name&
This command direct the loader to read the designated obCect program
from a library and treat
it as the primary loader input.
The general format of )E!ETE command is
)E!ETE sectAname
It instructs the loader to delete the named control sections from the sets
of programs loaded.
1(. i!e t*e f.n$tions of t*e #inFin% #oa'er.
1+
The linking loader performs the process of linking and relocation. It
includes the
operation of automatic library search and the linked programs are directly
loaded into the
memory.
1). i!e t*e 'ifferen$e 0etween #inFin% #oa'er an' #inFa%e
e'itors.
6inFin% #oa'er 6inFa%e e'itor
The relocation and linking is performed
each time the program is loaded
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
It produces a linked version of a program
and which is written in a file for later
execution
9ere the loading can be accomplished in a
single pass
Two passes are reMuired
1-. Define 'ynami$ #inFin%.
If the subroutine is loaded and linked to the program during its first call
%run time&,
then it is called as dynamic loading or dynamic linking.
1/. Write t*e a'!anta%e of 'ynami$ #inFin%.
It has the ability to load the routine only when they are needed.
The dynamic linking avoids the loading of entire library for each
execution.
13. W*at is meant 0y stati$ e>e$.ta0#e an' 'ynami$ e>e$.ta0#e,
In static executable, all external symbols are bound and ready to run. In
dynamic
executables some symbols are bound at run time.
14. W*at is s*are' an' "ri!ate 'ata,
The data divided among processing element is called shared data. If the
data is not
shared among processing elements then it is called private data.
25. Write t*e a0so#.te #oa'er a#%orit*m.
9e%in
$ead 9eader record
8erify program name and length
$ead first text record
Fhile record type R5 ;E= do
'egin
"oved obCect code to specified location in memory
$ead next obCect program record
End
Dump to address specified in End record
1(
+ACRO AROCESSORS
1. Define ma$ro "ro$essor.
"acro processor is system software that replaces each macroinstruction
with the
corresponding group of source language statements. This is also called as
expanding of
macros.
2. W*at 'o ma$ro e>"ansion statements mean,
These statements give the name of the macroinstruction being invoked
and the
arguments to be used in expanding the macros. These statements are
also known as macro
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
call.
&. W*at are t*e 'ire$ti!es .se' in ma$ro 'efinition,
"#$O A it identifies the beginning of the macro definition
"EG) A it marks the end of the macro definition
(. W*at are t*e 'ata str.$t.res .se' in ma$ro "ro$essor,
)E:T#' > the macro definitions are stored in a definition table i.e. it
contains a
macro prototype and the statements that make up the macro body.
G#"T#' > it is used to store the macro names and it contains two
pointers for each
macro instruction which indicate the starting and end location of macro
definition in
)E:T#'. it also serves as an index to )E:T#'
#$HT#' > it is used to store the arguments during the expansion of macro
invocations.
). Define $on'itiona# ma$ro e>"ansion.
If the macro is expanded depends upon some conditions in macro
definition
%depending on the arguments supplied in the macro expansion& then it is
called as conditional
macro expansion.
-. W*at is t*e .se of ma$ro time !aria0#e,
"acro time variable can be used to store working values during the macro
expansion.
#ny symbol that begins with the character E and then is not a macro
instruction parameter is
assumed to be a macro time variable.
/. W*at are t*e statements .se' for $on'itiona# ma$ro
e>"ansion,
I:AE!4EAEG)I: statement
F9I!EAEG)F statement
3. W*at is meant 0y "ositiona# "arameters,
1*
If the parameters and arguments were associated with each other
according to their
positions in the macro prototype and the macro invocation statement,
then these parameters in
macro definitions are called as positional parameters.
4. Consi'er t*e ma$ro 'efinition
='efine DISA6AD :E2AR; Arintf :HE2AR @ I'JnKL E2AR;
E>"an' t*e ma$ro instr.$tion DISA6AD :ANS;
#ns.: ?rintf %SE@?$ 5 TdUnV, #G4&
15. W*at are Fnown as neste' ma$ro $a##,
The statement, in which a macro calls on another macro, is called nested
macro call.
In the nested macro call, the call is done by outer macro and the macro
called is the inner
macro.
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
11. How t*e ma$ro is "ro$esse' .sin% two "asses,
?ass(: processing of definitions
?ass *:actualAmacro expansion.
12. i!e t*e a'!anta%e of #ine 0y #ine "ro$essors.
It avoids the extra pass over the source program during assembling.
It may use some of the utility that can be used by language translators
so that can be
loaded once.
1&. W*at is meant 0y #ine 0y #ine "ro$essor,
This macro processor reads the source program statements, process the
statements and
then the output lines are passed to the language translators as they are
generated, instead
of being written in an expanded file.
1(. i!e t*e a'!anta%es of %enera#<".r"ose ma$ro "ro$essors.
The programmer does not need to learn about a macro facility for each
compiler.
Overall saving in software development cost and maintenance cost.
1). W*at is meant 0y %enera#<".r"ose ma$ro "ro$essors,
The macro processors that are not dependent on any particular
programming
language, but can be used with a variety of different languages are
known as general purpose
macro processors.
Eg. The E!EG# macro processor.
1-. W*at are t*e im"ortant fa$tors $onsi'ere' w*i#e 'esi%nin%
%enera# ".r"ose ma$ro
"ro$essors,
comments
11
grouping of statements
tokens
syntax used for macro definitions
1/. W*at is t*e sym0o# .se' to %enerate .ni?.e #a0e#s,
W symbol is used in macro definition to generate uniMue symbols. Each
macro
expansion the W symbol is replaced by W@@, where @@ is the alpha
numeric character.
13. How t*e neste' ma$ro $a##s are e>e$.te',
The execution of nested macro call follows the !I:O rule. In case of nested
macro
calls the expansion of the latest macro call is completed first.
14. +ention t*e tasFs in!o#!e' in ma$ro e>"ansion.
identify the macro calls in the program
the values of formal parameters are identified
maintain the values of expansion time variables declared in a macro
expansion time control flow is organiOed
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
determining the values of seMuencing symbols
expansion of a model statement is performed
25. How to 'esi%n t*e "ass str.$t.re of a ma$ro assem0#er,
To design the structure of macroAassembler, the functions of macro
preprocessor and
the conventional assembler are merged. #fter merging, the functions are
structured into
passes of the macro assembler.
TE2T EDITORS
1. Define intera$ti!e e'itor,
#n interactive editor is a computer program that allows a user to create
and revise a
target document. The term document includes obCects such as computer
programs, text,
eMuations, tables, diagrams, line art, and photographs any thing that one
might find on a
printed page.
2. W*at are t*e tasFs "erforme' in t*e e'itin% "ro$ess,
2 tasks
4elect the part of the target document to be viewed and manipulated.
)etermine how to format this view onAline and how to display it.
4pecify and execute operations that modify the target document.
Bpdate the view appropriately.
12
&. W*at are t*e t*ree $ate%ories of e'itorMs 'e!i$es,
Text deviceX 4tring devices
'utton deviceXhoice devices
!ocator device
(. W*at is t*e f.n$tion "erforme' in e'itin% "*ase,
In the actual editing phase, the target document is created or altered with
a set of
operations such as insert, delete, replace, move and copy.
). Define 6o$ator 'e!i$e,
!ocator devices are twoAdimensional analogAtoAdigital converters that
position a
cursor symbol on the screen by observing the user=s movement of the
device. The most
common such devices for editing applications are the mouse and the data
tablet.
-. W*at is t*e f.n$tion "erforme' in !oi$e in".t 'e!i$e,
8oiceAinput devices, which translate spoken words to their textual
eMuivalents, may
prove to be the text input devices of the future. 8oice recogniOers are
currently available for
command input on some systems.
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
/. W*at are $a##e' toFens,
The lexical analyOer tracks the source program one character at a time by
making the
source program into seMuence of atomic units is called tokens.
3. Name some of ty"i$a# toFens.
Identifiers, keywords, constants, operators and punctuation symbols such
as commas
and parentheses are typical tokens.
4. W*at is meant 0y #e>eme,
The character that forms a token is said to be a lexeme.
15. +ention t*e main 'isa'!anta%e of inter"reter.
The main disadvantage of interpreter is that the execution time of
interpreted program
is slower than that of a corresponding compiled obCect program.
11. W*at is meant 0y $o'e o"timiNation,
The code optimiOation is designed to improve the intermediate code,
which helps the
obCect program to run faster and takes less space.
12. W*at is error *an'#er,
The error handler is used to check if there is an error in the program. If
any error, it
should warn the programmer by instructions to proceed from phase to
phase.
1.
1&. Name some of te>t e'itors.
line editors
stream editors
screen editors
word processors
structure editors
1(. W*at for 'e0.% monitors are .se',
)ebug monitors are used in obtaining information for localiOation of
errors.
1). +ention t*e feat.res of wor' "ro$essors.
moving text from one place to another
merging of text
searching
word replacement
1-. W*at are t*e "*ases in "erformin% e'itin% "ro$ess,
Traveling phase
:iltering phase
:ormatting phase
Editing phase
1/. Define tra!e#in% "*ase.
The phase specifies the region of interest. Traveling is achieved using
operations
such as next screenful, bottom, find pattern.
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
13. 7i#terin% "*ase.
The selection of what is to be viewed and manipulated in given by
filtering.
14. E'itin% "*ase
In this phase, the target document is altered with the set of operations
such as insert,
delete, replace, move and copy.
25. Define .ser interfa$e,
Bser interface is one, which allows the user to communicate with the
system in order
to perform certain tasks. Bser interface is generally designed in a
computer to make it easier
to use.
21. Define in".t 'e!i$e,
1/
Input device is an electromechanical device, which accepts data from the
outside
world and translates them into a form, which the computer can interpret.
**.)efine output devices
Output devices the user to view the elements being edited and the results
of the editing
operations.
2&. W*at are t*e met*o's in Intera$tion #an%.a%e of a te>t
e'itor,
Typing >oriented or text command oriented method
:unction key interfaces
menu oriented method
2(. Define intera$ti!e 'e0.%%in% systems.
#n interactive debugging system provides programmers with facilities
that aid in the
testing and debugging of programs.
)ebugging functions and capabilities
$elationship with other parts of the system
Bser interface criteria.
2). Define e'itor str.$t.re.
The command language processor accepts input from the users input
devices and
analyOes the tokens and syntactic structure of the commands.
2-. i!e t*e $om"onents of e'itor str.$t.re
2 components
Editing component
Traveling component
8iewing component
)isplay component
2/. W*at are t*e 0asi$ ty"es of $om".tin% en!ironments .se' in
e'itorMs f.n$tions,
Editor=s function in three basic types of computing environments
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m
i. Time sharing ii. 4tandAalone iii. )istributed
w
w
w
.
r
e
j
i
n
p
a
u
l
.
c
o
m

S-ar putea să vă placă și