8/13/2019 SS lab manual R 2004
1/48
EX: NO: 1
PROGRAM TO SYMBOL TABLE
AIM:
To write a C program to create a symbol table and do the insertion,
modification, search and display operations.
ALGORITHM:
1. Start the program.
2. Create a menu through which we can create a symbol table and perform operations
as insert, modify, search and display.
3. Create a symbol table with fields as variable and value using !create" option.
#ntries may be added to the table while it is created itself.
$. %ppend new contents to the symbol table with the constraint that there is no
duplication of entries, using !insert" option.
&. 'odify e(isting content of the table using modify option.
). *se display option to display the contents of the table.
1
8/13/2019 SS lab manual R 2004
2/48
PROGRAM:
+includestdio.h-
+includeconio.h-
+includestdlib.h-
+includestring.h-struct table
char var/10
int value
struct table tbl/20
int i,4,n
void create56
void modify56
int serach5char variable/,int n6
void insert56void display56
void main56
int ch,result70
char v/10
clrscr56
do
printf58 1.Create 9n86printf58 2.:nsert 9n86
printf58 3.'odify 9n86
printf58 $.Search 9n86
printf58 &.;isplay 9n86
printf58 ).#(it 9n86
printf58#nter the Choicech6
switch5ch6
case 1
8/13/2019 SS lab manual R 2004
3/48
result7search5v,n6
if5result7706
printf58The variable does not belong to the table86
else
printf58The location of the variable is =d 9n The value of =s is =d 8,
result,tbl/result.var,tbl/result.value6 brea?
case &tbl/i.var/07BB6
printf58The variable should start with an alphabet 9n #nter correctvariable name
8/13/2019 SS lab manual R 2004
4/48
void insert56
if5i-7206
printf58cannot insert. table is full9n86
else
nAA
printf58#nter the variable and the valuetbl/n.value6
chec?>tbl/i.var/07BB6
printf58The variable should start with an alphabet 9n #nter the correct variable
name
8/13/2019 SS lab manual R 2004
5/48
scanf58=s=d8,tbl/result.var,>tbl/result.value6
chec?>tbl/i.var/07BB6
printf58The variable should start with an alphabet 9n #nter the correct variablename
8/13/2019 SS lab manual R 2004
6/48
OUTPUT:
1.Create
2.:nsert
3.'odify
$.Search
&.;isplay).#(it
#nter the Choice
8/13/2019 SS lab manual R 2004
7/48
2.:nsert
3.'odify
$.Search
&.;isplay
).#(it
#nter the Choice
8/13/2019 SS lab manual R 2004
8/48
EX: NO: 2
IMPLEMENTATION OF A PASS 1 OF A TWO PASS ASSEMBLER
AIM:
To implement a pass1 of a two pass assembler using C .
ALGORITHM:
1. Eead the input line.
2. Chec? to see if the opcode in the input line is !ST%ET".
5i6Iind if there is any operand field after ST%ET, if so that indicates the
location from which the program has to be loaded in the memory, so
initialiLe the GMCCTE to the operand value.
5ii6Mtherwise if there is no value in the operand field the GMCCTE is set to
Lero and the program starts loading from the starting address Lero.
3. Nrite the line to the intermediate file.
$. Oow start the following processing for the other lines in the program, if it is
not a comment line, until the opcode is !#O;"
5a6:f there is a symbol in the label field.
5i6Chec? the symbol table to see if has already been stored over there. :f so
then it is a duplicate symbol, the error message should be displayed.
5ii6Mtherwise the symbol is entered into the SP'T%F, along with the
memory address in which it is stored.
5b6:f there is an opcode in the line read.
5i6Search the MQT%F to see if the opcode is present, if so increment the
location counter by 3.
5ii6:f the opcode is !NME;", increment the location counter by 3
5iii6 :f the opcode is !FPT#", increment the location counter by 1.
5iv6 :f the opcode is !E#SN", increment the location counter by the
integer eRuivalent of the operand value 3.
J
8/13/2019 SS lab manual R 2004
9/48
5v6:f the opcode is !E#SF", increment the location counter by the
integer eRuivalent of the operand value.
5c6Nrite each and every line processed to the intermediate file along with their
location counters.
&. Subtract the starting address of the program from the final value of the
GMCCTE, to calculate the length of the program.
). Close all the opened files and e(it.
8/13/2019 SS lab manual R 2004
10/48
PROGRAM:
+includestdio.h-
+includeconio.h-
+includestring.h-
struct optab
char mnem/10,mcode/20
struct optab op/)78G;%8,8&C8,8G;8,80$8,8ST%8,80&8,
8%;;8,8$C8,8T:8,80J8,8UGT8,80&8
void main56
char opcode/10,operand/10,label/10,flag
int i,locctr,curaddr
I:G# fp1,fp2,fp3
clrscr56fp17fopen581in.dat8,8r86
fp27fopen58inter.dat8,8w86
fp37fopen58symbol.dat8,8w86
fscanf5fp1,8=s9t=s9n8,opcode,operand6
if5strcmp5opcode,8ST%ET867706
locctr7atoi5operand6
fscanf5fp1,8=s9t=s9t=s9n8,label,opcode,operand6
while5strcmp5opcode,8#O;86@706
flag7BfB
curaddr7locctr
if5strcmp5label,8O*GG86@706
fprintf5fp3,8=s9t=d9n8,label,curaddr6
for5i70i7&iAA6
if5strcmp5opcode,op/1.mnem67706
flag7BtB
if5flag77BtB6
locctrA73else if5strcmp5opcode,8NME;867706
locctrA73
else if5strcmp5opcode,8E#SN867706
locctrA73atoi5operand6
else if5strcmp5opcode,8E#SF867706
locctrA7atoi5operand6
else if5strcmp5opcode,8FPT#867706
10
8/13/2019 SS lab manual R 2004
11/48
locctrA7strlen5operand6
else
printf58=d9t=s9t=s9t=s9t invalid statement9n8,curaddr,label,opcode,operand6
fprintf5fp2,8=d9t=s9t=s9n8,curaddr,opcode,operand6
fscanf5fp1,8=s=s=s8,label,opcode,operand6
fprintf5fp2,89tO*GG9t#O;86
getch56
OUTPUT:
11
8/13/2019 SS lab manual R 2004
12/48
1IN.DAT:
ST%ET 2000
O*GG G; V#EM
E#Q#%T G;% %GQW%O*GG %;; F#T%
O*GG ST% H%''%
O*GG T: ;#GT%
O*GG UGT E#Q#%T
V#EM FPT# 0
%GQW% E#SF 1
F#T% E#SN 1
H%''% E#SN 1
;#GT% NME; 2
O*GG #O;
INTER.DAT:
2000 G; V#EM
2003 G;% %GQW%
2003 %;; F#T%
2003 ST% H%''%
2003 T: ;#GT%
2003 UGT E#Q#%T
2003 FPT# 0
200$ E#SF 1200& E#SN 1
200J E#SN 1
2011 NME; 2
O*GG #O;
SYMBOL.DAT:
E#Q#%T 2003
V#EM 2003
%GQW% 200$
F#T% 200&H%''% 200J
;#GT% 2011
RESULT:
Thus the Qass1 of a assembler were implemented and e(ecuted.
EX: NO: 3
12
8/13/2019 SS lab manual R 2004
13/48
IMPLEMENTATION OF A PASS2 OF A TWO PASS ASSEMBLER
AIM:
To Nrite a C program for pass2 of a two pass assembler.
ALGORITHM:
1. Eead the first line from the intermediate file
2. Chec? to see if the opcode from the first line read is !ST%ET".
5i6 :f so then write the label, opcode and operand field values of the
corresponding statement directly to the final output file.
3. Star the following processing, for the other lines in the intermediate file if it isnot a comment line until an !#O;" statement is reached
5i6 Start writing the location counter, opcode and operand fields of the
corresponding statement to the output file, along with the ob4ect code. The
ob4ect code is found by assembling each statement opcodes machine
eRuivalent with the label address.
5ii6 :f there is no symbolXlabel in the operand field, then the operand address is
assigned as Lero, and it is assembled with the ob4ect code of theinstruction.
5iii6 :f the opcode is FPT#,NME;,E#SN,etc convert the constants to the
ob4ect code.
$. Close the opened files and e(it.
PROGRAM:
13
8/13/2019 SS lab manual R 2004
14/48
+includestdio.h-
+includeconio.h-
+includestring.h-
struct optab
char mnem/10,mcode/20
struct optab op/)78G;%8,8&C8,8G;8,80$8,8ST%8,80&8,
8%;;8,8$C8,8T:8,80J8,8UGT8,80&8
void main56
char opcode/10,operand/10,label/10,ob4/10,addr/10,addr1/10,
symbol/10
int i
I:G# fp1,fp2,fp3
clrscr56
fp17fopen5822in.dat8,8r86fp27fopen5822sym.dat8,8r86
fp37fopen5822out.dat8,8w86
fscanf5fp1,8=s9t=s9t=s9t=s9n8,addr,label,opcode,operand6
while5@feof5fp166
strcpy5ob4,8 86
for5i70i7&iAA6
if5strcmp5opcode,op/i.mnem67706
strcpy5ob4,op/i.mcode6
rewind5fp26
while5@feof5fp266
fscanf5fp2,8=s=s9n8,symbol,addr16
if5strcmp5symbol,operand67706
strcat5ob4,addr16
if55strcmp5opcode,8FPT#867706YY5strcmp5opcode,8NME;8677066
strcat5ob4,operand6
fprintf5fp3,8=s9t=s9t=s9t=s9t=s9n8,addr,label,opcode,operand,ob46printf58=s9t=s9t=s9t=s9t=s9n8,addr,label,opcode,operand,ob46
fscanf5fp1,8=s9t=s9t=s9t=s9n8,addr,label,opcode,operand6
getch56
OUTPUT:
1$
8/13/2019 SS lab manual R 2004
15/48
22IN.DAT:
2000 G; V#EM
2003 G;% %GQW%
2003 %;; F#T%
2003 ST% H%''%2003 T: ;#GT%
2003 UGT E#Q#%T
2003 FPT# 0
200$ E#SF 1
200& E#SN 1
200J E#SN 1
2011 NME; 2
O*GG #O;
22SYM.DAT:
E#Q#%T 2003
V#EM 2003
%GQW% 200$
F#T% 200&
H%''% 200J
;#GT% 2011
22OUT.DAT:
2000 G; V#EM 2003G;% %GQW% 2003 %;;
F#T% 2003 ST% H%''% 0&200J
2003 T: ;#GT% 2003
UGT E#Q#%T 2003 FPT#
0 200$ E#SF 1
200& E#SN 1 200J
E#SN 1 2011 NME;
RESULT:
Thus the pass2 of a assembler were implemented and e(ecuted.
EX.NO:4
1&
8/13/2019 SS lab manual R 2004
16/48
IMPLEMENTATION OF SINGLE PASS ASSEMBLER
AIM:
To implement a single pass assembler by using C language.
ALGORITHM:
1. Start the program.
2. %ssembler simply generates ob4ect code as it scans the source program.
3. :f the instruction operand is a symbol that has not yet been defined, the
operand address is omitted when the instruction is assembled.
$. This symbol is entered into the symbol table, as an undefined symbol with.
&. Nhen the definition of the symbol is encountered, the proper address is
inserted in a list associated with that symbol.
). Nhen nearly half of the program translation is over some of the forward
reference problems that e(isted earlier would have been resolved, while others
might have been added.
K. Continue the process to the end of the program to fill all the forward
references properly.
J. %t the end of the program, symbol table entries still mar?ed with are
undefined symbols.
. Stop the program
PROGRAM:
1)
8/13/2019 SS lab manual R 2004
17/48
+includestdio.h-
+includeconio.h-
+includestring.h-
+includestdlib.h-
+define '% 10
struct input
char label/10,opcode/10,operand/10,mnemonic/&
int loc
struct input table/'%
struct symtab
char sym/10
int f,val,ref
struct symtab symtbl/'%void main56
int f1,i71,471,flag,locctr,(
char add/10,code/10,mnemcode/&
I:G# fp1,fp2,fp3
clrscr56
fp17fopen58sin.dat8,8r86
fp27fopen58optab.dat8,8r86
fp37fopen58sout.dat8,8w86
fscanf5fp1,8=s=s=s8,table/i.label,table/i.opcode,table/i.operand6if5strcmp5table/i.opcode,8ST%ET867706
locctr7atoi5table/i.operand6
iAA
fscanf5fp1,8=s=s=s8,table/i.label,table/i.opcode,table/i.operand6
else locctr70
while5strcmp5table/i.opcode,8#O;86@706
if5strcmp5table/i.label,886@706
for5(71(4(AA6
f170
if55strcmp5symtbl/(.sym,table/i.label67706>>5symtbl/(.f77166
symtbl/(.val7locctr
symtbl/(.f70
1K
8/13/2019 SS lab manual R 2004
18/48
table/symtbl/(.ref.loc7locctr
f171
brea?
if5f17706
strcpy5symtbl/4.sym,table/i.label6
symtbl/4.val7locctr
symtbl/4.f70
4AA
fscanf5fp2,8=s=s8,code,mnemcode6
while5strcmp5code,8#O;86@706
if5strcmp5table/i.opcode,code67706
strcpy5table/i.mnemonic,mnemcode6
locctrA73
for5(71(74(AA6
flag70
if5strcmp5table/i.operand,symtbl/(.sym67706
flag71
if5symtbl/(.f7706table/i.loc7symtbl/(.val
brea?
if5flag@716
strcpy5symtbl/4.sym,table/i.operand6
symtbl/4.f71
symtbl/4.ref7i
4AA
fscanf5fp2,8=s=s8,code,mnemcode6
rewind5fp26
if5strcmp5table/i.opcode,8NME;867706
locctrA73
1J
8/13/2019 SS lab manual R 2004
19/48
strcpy5table/i.mnemonic,B90B6
table/i.loc7atoi5table/i.operand6
else if5strcmp5table/i.opcode,8E#SN867706
locctrA7535atoi5table/i.operand666strcpy5table/i.mnemonic,B90B6
table/i.loc7atoi5B90B6
else if 5strcmp5table/i.opcode,8FPT#867706
AAlocctr
if55table/i.operand/077BCB6YY5table/i.operand/077BB66
table/i.loc75int6table/i.operand/2
else
table/i.loc7locctr
iAA
fscanf5fp1,8=s=s=s8,table/i.label,table/i.opcode,table/i.operand6
for5(71(7i(AA6
fprintf5fp3,8=s9t=s9t=s9t
=s9n8,table/(.label,table/(.opcode,table/(.operand,strcat5table/(.mnemonic
,itoa5table/(.loc,add,10666
for5(71(4(AA6
printf58=s9t=d9n8,symtbl/(.sym,symtbl/(.val6
getch56
OUTPUT:
SIN.DAT
ST%ET )000
US*F CGMMQ
US*F EGMMQ
%GQW% NME; 23
F#T% E#SN 3
H%''% FPT# CBVB;#GT% E#SF $
CGMMQ G;% %GQW%
EGMMQ ST% F#T%
G;CW H%''%
STCW ;#GT%
#O;
OPTAB.DAT
1
8/13/2019 SS lab manual R 2004
20/48
ST%ET
US*F $J
G;% 1$
ST% 03
G;CW &3STCW &K
#O;
SOUT.DAT
ST%ET )000 0
US*F CGMMQ $J)01
US*F EGMMQ $J)022
%GQW% NME; 23 23F#T% E#SN 3 0
H%''% FPT# CBVB 0
;#GT% E#SF $ 0
CGMMQ G;% %GQW% 1$)00)
EGMMQ ST% F#T% 03)00
G;CW H%''% &3)01J
STCW ;#GT% &K)01
#O; 23
RESULT:
Thus the single pass assembler was successfully implemented.
EX: NO: 5
20
8/13/2019 SS lab manual R 2004
21/48
IMPLEMENTATION OF A MACRO PROCESSOR
AIM:
To implement a C program for macro processor.
ALGORITHM:
1. Het the statement from the input file.
2. Irom the line read, chec? if the opcode is the directive !'%CEM", if so then
the number of macro n must be incremented.
3. Eepeat step 1 and 2 until and end of file is encountered.
$. Mpen n number of files in write mode. These files will later hold the body of
the n macros respectively.
&. Eewind the input file pointer.
). :f the opcode is !macro"
5i6#nter the name present in the operand field into the array named m.
5ii6Nrite the line to the e(panded output file.
5iii6#nter lines in the body of each macro into the corresponding files already
opened in step$.
5iv6Nrite the body of each macro to the e(panded output files also, until a
!mend" is reached.
K. Mtherwise if the opcode is !call" the line must be a macro invocation
statement so, the macro body is retrieved from the corresponding file and
written to the e(panded output file.
J. Nrite all the remaining lines directly to the e(panded file.
21
8/13/2019 SS lab manual R 2004
22/48
PROGRAM:
+includestdio.h-
+includeconio.h-
+includestring.h-
+includestdlib.h-void main56
char n1,n,c1,i
char fn/10/10,ilab/20,iop/20,m/20/3,oper/20,opd/20
I:G# f1,f2,p/&
clrscr56
n70
f17fopen58macroin.dat8,8r86
while5@feof5f166
fscanf5f1,8=s=s=s8,ilab,iop,oper6if5strcmp5iop,8macro867706
nAA
printf58no.of macros7=d9n8,n6
n17n
printf58#nter the te(t filename
8/13/2019 SS lab manual R 2004
23/48
for5i70in1iAA6
p/i7fopen5fn/i,8r86
f27fopen58macroout.dat8,8w86
rewind5f16
fscanf5f1,8=s=s=s8,ilab,iop,oper6while5@feof5f166
if5strcmp5iop,8call867706
for5i70in1iAA6
if5strcmp5m/i,oper67706
rewind5p/i6
fscanf5p/i,8=s=s=s8,ilab,iop,oper6
while5@feof5p/i66
fprintf5f2,8=s=s=s9n8,ilab,iop,oper6
c171
fscanf5p/i,8=s=s=s8,ilab,iop,oper6
brea?
if5c1@716fprintf5f2,8=s=s=s9n8,ilab,iop,oper6
c170
fscanf5f1,8=s=s=s8,ilab,iop,oper6
fprintf5f2,8=s=s=s9n8,ilab,iop,oper6
getch56
23
8/13/2019 SS lab manual R 2004
24/48
OUTPUT:
no.of macros72
#nter the te(t filenameloc6
while5strcmp5ip,8E86@706
strcpy5table/count.csect,89086
3$
8/13/2019 SS lab manual R 2004
35/48
strcpy5table/count.symname,ip6
table/count.add7locAstart
table/countAA.length70
fscanf5f1,8=s=l(8,ip,>loc6
while5strcmp5ip,8T86@706fscanf5f1,8=s8,ip6
if5strcmp5ip,8T867706
while5strcmp5ip,8#86@706
fscanf5f1,8=s8,ip6
fscanf5f1,8=s8,ip6
start7startAlength
for5i70icountiAA6
fprintf5f2,8=s9t=s9t=l(9t
=d9n8,table/i.csect,table/i.symname,table/i.add,table/i.length6getch56
OUTPUT:
L!IN.DAT
W QEMH% 000000 0000K0
; G:ST 0000$0 #O;% 0000&$
E G:STF #O;F G:STC #O;CT 000020 10 03201; KK10000$ 1&001$
' 00002$ 0& AG:STF
' 0000&$ 0) AG:STC
' 0000&J 0) A#O;C
' 0000)$ 0) AG:STF
# 000000
L!OUT.DAT
CS#CT Tsymname Taddress Tlength
QEMH% 3000 K0 G:ST 30$0 0
#O;% 30&$ 0
RESULT:
Thus the pass 1 of a direct lin?ing loader were successfully implemented
3&
8/13/2019 SS lab manual R 2004
36/48
EX: NO: "
IMPLEMENTATION OF A PASS2 OF A DIRECT LIN!ING LOADER
AIM:
To implement a pass2 of a direct lin?ing loader using C.
ALGORITHM:
1. %ssign the control section address in a variable, CS%;E.
2. Eead the header record.
5i6Irom the information available in the header record, store the control
section length in a variable.3. ;o the following process until an end record is reached.
5i6:f the subseRuent records read is a te(t record T, and if the ob4ect code is
in character form convert it into machine representation ,and move the ob4ect
code from the record to the memory location control sections address plus
the specified address in the te(t record.
5ii6:f the subseRuent records read is modification record ' then search for
the modifying symbol name in the e(ternal symbol table created by pass1 ifit is found then add, or subtract the corresponding symbol address found
with the value starting at the location
$. %dd the control section length to the current control sections address to find
the address of the ne(t control section, and repeat the entire process until there
are no more input.
3)
8/13/2019 SS lab manual R 2004
37/48
PROGRAM:
+includestdio.h-
+includeconio.h-
+includestdlib.h-
+includestring.h-struct e(ttable
char csect/10,sname/10
int padd,plen
estab/20
struct ob4code
char code/1&
int add
ob4co/&00
void main56
I:G# f1,f2,f3
int
i,4,(,y,n70,num70,inc70,count70,record70,pstart,e(eloc,start,te(tloc,loc,mloc/
30,te(len,mlen/30,len,location
long int newadd
char add1,operation,lbl/10,ip/10,label/30/10,addr/10
clrscr56
f17fopen582lin.dat8,8r86
f27fopen582l?out.dat8,8r86f37fopen582lin?out.dat8,8w86
rewind5f16
rewind5f26
rewind5f36
while5@feof5f266
fscanf5f2,8=s=s=d
=d8,estab/num.csect,estab/num.sname,>estab/num.padd,>estab/num.plen
6
numAA
e(eloc7estab/0.padd
loc7e(eloc
start7loc
while5@feof5f166
fscanf5f1,8=s8,ip6
if5strcmp5ip,8W867706
3K
8/13/2019 SS lab manual R 2004
38/48
fscanf5f1,8=s8,ip6
for5i70inumiAA6
if5strcmp5ip,estab/i.csect67706
pstart7estab/i.paddbrea?
while5strcmp5ip,8T86@706
fscanf5f1,8=s8,ip6
do
if5strcmp5ip,8T867706
fscanf5f1,8=d8,>te(tloc6
te(tloc7te(tlocApstartfor5i70i5te(tlocZloc6iAA6
strcpy5ob4co/inc.code,8((86
ob4co/incAA.add7startAA
fscanf5f1,8=d8,>te(len6
loc7te(tlocAte(len
else if5strcmp5ip,8'867706
fscanf5f1,8=d8,>mloc/record6
mloc/record7mloc/recordApstart
fscanf5f1,8=d8,>mlen/record6
fscanf5f1,8=s8,label/recordAA6
else
len7strlen5ip6
(70
for5i70ileniAA6
ob4co/inc.code/(AA7ip/i
if5(-16
ob4co/incAA.add7startAA
(70
3J
8/13/2019 SS lab manual R 2004
39/48
fscanf5f1,8=s8,ip6
while5strcmp5ip,8#86@706
if5strcmp5ip,8#867706
fscanf5f1,8=s8,ip6
for5n70nrecordnAA6
operation7label/n/0
len7strlen5label/n6
for5i71ileniAA6
lbl/iZ17label/n/i
lbl/lenZ17B90B
len70
strcpy5addr,89086
location7mloc/nZe(elocloc7location
count70
while5lenmlen/n6
strcat5addr,ob4co/locationAA.code6
countAA
lenA72
for5i70inumiAA6
if5strcmp5lbl,estab/i.sname67706brea?
switch5operation6
case BABadd1,106A5long int6estab/i.padd
brea?
case BZBadd1,106A5long int6estab/i.padd
brea?
ltoa5newadd,addr,106
(70y70
while5count-06
ob4co/loc.code/(AA7addr/yAA
if5(-16
(70
locAA
countZZ
3
8/13/2019 SS lab manual R 2004
40/48
count70
n70
fprintf5f3,8=d9t8,ob4co/0.add6for5i70iinciAA6
fprintf5f3,8=s8,ob4co/i.code6
nAA
if5n-36
fprintf5f3,89t86
n70
countAA
if5count-36
fprintf5f3,89n=d9t8,ob4co/iA1.add6
count70
getch56
$0
8/13/2019 SS lab manual R 2004
41/48
OUTPUT:
2LIN.DAT
W QEMHF 000000 0000J0; G:STF 0000)0 #O;F 0000K0
E G:ST% #O;% G:STC #O;C
T 000020 11 03100000 KK202K 01&00000
' 0000$$ 0& AG:ST%
' 0000K0 0) A#O;%
' 0000K$ 0) A#O;%
' 0000)$ 0) AG:STF
# 000000
2LOUT.DAT
QEMH% 2000 K0
G:ST% 20$0 0
#O;% 20&$ 0
2LIN!OUT.DAT
2000 (((((((( (((((((( (((((((( ((((((((
201) (((((((( 03201;1KK 10213$1& 001$ ((((
2032 (((((((( (((((((( (((((((( ((((((((
RESULT:
Thus the pass2 of a direct lin?ing loader was implemented successfully.
$1
8/13/2019 SS lab manual R 2004
42/48
EX: NO: 1#
IMPLEMENTATION OF A SIMPLE EDITOR
AIM: To write a C program to implement a simple editor
ALGORITHM:
1. Qrovide the blan? screen for the user to type the document
2. :nstruct the user to enter the te(t using the editor.
3. ;isplay the entered character on the screen.
$. Characters displayed on the screen are stored in a character array.
&. Specify if the content has to be saved or not.
). :f S%D# option is selected
5i6Het the data file name from the user
5ii6Mpen the file in write mode
5iii6'ove the content of the character array to the file and close the file.
K. :f MQ#O option is selected
5i6Mpen the data file in the read mode
5ii6Eead one character at a time from the file and move it to the character
array
5iii6Eepeat the above steps until the end of file is reached
5iv6;isplay the characters from the character array on the screen.
J. Iinally close the te(t editor and e(it.
$2
8/13/2019 SS lab manual R 2004
43/48
PROGRAM:
+includestdio.h-
+includeconio.h-+includectype.h-
+includedos.h-
+includeiostream.h-
+includefstream.h-
char filename/1&
char buff/1000
int c(,cy,count
void c[pos56
c(7where(56
cy7wherey56goto(y53&,16
cout89nType your te(t and then press escape ?ey9n8
goto(y5100,1006
cprintf58=2d=2d8,cy,c(6
goto(y5c(,cy6
void main56
char ch,c
ofstream outfileifstream infile
clrscr56
c[pos56
c(7where(56
cy7wherey56
while5c@72K6
c7getch56
switch5c6
case J0
8/13/2019 SS lab manual R 2004
44/48
case 32> c7&K66
cprintf58=c8,c6
brea?
buff/countAA7c
c[pos56
cprintf589n9n ;o * want to Save\5yXn6c6
if55c77ByB6YY5c77BPB66
cprintf589n9n#nter the filename with e(tension in J characters only
8/13/2019 SS lab manual R 2004
45/48
OUTPUT:
simple te(t editor program
Type your te(t and then press escape ?ey
213
;o * want to Save\5yXn6
8/13/2019 SS lab manual R 2004
46/48
EX: NO: 11
IMPLEMENTATION OF A MACRO SUBSTITUTION
AIM:
To write a C program to perform a macro substitution operations such as
addition, subtraction, multiplication and division.
ALGORITHM:
1. Start the program.
2. :nclude the necessary header files.
3. :nitialiLe and assign the values to the variables.
$. :mplement the functions and print the result.
&. Stop the program.
$)
8/13/2019 SS lab manual R 2004
47/48
PROGRAM:
+includestdio.h-
+includeconio.h-
void main56
int c,d,e,f
int add56
int sub56
int mul56
int div56
c7add56
d7sub56
e7mul56
f7div56
printf589n The value of addition is =d8,c6printf589n The value of subtraction is =d8,d6
printf589n The value of multiplication is =d8,e6
printf589n The value of division is =d8,f6
getch56
int add56
int a,b,c
printf589n#nter the value of aa6
printf589n#nter the value of bb6
c7aAb
return c
int sub56
int a,b,d
d7aZb
return d
int mul56
int a,b,e
e7ab
return e
int div56
int a,b,f
f7aXb
$K
8/13/2019 SS lab manual R 2004
48/48
return f
OUTPUT:
#nter the value of a