List of the Experiments 01IMPLEMENTATION OF SYMBOL TABLE 0IMPLEMENTATION OF PASS 1 OF A TWO PASS ASSEMBLER 0!IMPLEMENTATION OF PASS OF A TWO PASS ASSEMBLER 0"IMPLEMENTATION OF A SIN#LE PASS ASSEMBLER 0$IMPLEMENTATION OF AN ABSOLUTE LOA%ER 0&IMPLEMENTATION OF A RELO'ATIN# LOA%ER 0(IMPLEMENTATION OF PASS 1 OF A %IRE'T LIN)IN# LOA%ER 0*IMPLEMENTATION OF PASS OF A %IRE'T LIN)IN# LOA%ER 0+IMPLEMENTATION OF A SIN#LE PASS MA'RO PRO'ESSOR 10IMPLEMENTATION OF A TWO PASS MA'RO PRO'ESSOR 11IMPLEMENTATION OF A SIMPLE TE,T E%ITOR Ex- No- 1 %ATE. IMPLEMENTATION OF SYMBOL TABLE Aim. To implement a symbol table with functions to create, insert, modify, search, and display, using C language. A/0orithm. Step 1: Design a menu through which we can create a symbol table and perform operations as insert, modify, search and display. Step 2: Create a Symbol table with fields as ariable! and alue! using create"# option. Step $: %ntries may be added to the table while it!s created itself. Step &: 'ppend new contents to the symbol table with the constraints that there is no duplication of entries, using insert "# option. Step (: )odify e*isting content of the table using modify "# option. Step +: ,se display "# option to display the contents of the table. Pro0r1m. -include .stdio.h/ -include .conio.h/ -include .stdlib.h/ -include .string.h/ struct table 0 char ar11234 int alue4 54 struct table tb112234 int i,6,n4 oid create"#4 oid modify"#4 int search"char ariable13,int n#4 oid insert"#4 oid display"#4 oid main"# 0 int ch,result724 char 11234 do 0 clrscr"#4 printf"89n1. C:%'T%9n2. ;<S%:T9n$. )=D;>?9n&. S%':C@9n(. D;SAB'?9n+. %C;T 8#4 printf"89n %nter your choice : 8#4 scanf"8Dd8,Ech#4 switch"ch# 0 case 1: create"#4breaF4 case 2: insert"#4breaF4 case $: modify"#4breaF4 case &: printf"89n %nter the ariable to be searched for : 8#4 scanf"8Ds8,#4 result7search",n#4 if"result772# printf"89n The ariable doest not belong to the table.8#4 else printf"89n Gariable7Ds9tGalue7Dd9tBocation7 Dd8,tb11result3.ar,tb11result3.alue,result#4 getch"#4 breaF4 case (: display"#4breaF4 case +: e*it"1#4 5 5 while"chH7+#4 getch"#4 5 oid create"# 0 printf"89n%nter the number of entries: 8#4 scanf"8Dd8,En#4 printf"89n%nter the ariable and the alue:9n8#4 for"i714i.7n4iII# 0 scanf"8DsDd8,tb11i3.ar,Etb11i3.alue#4 checF: if"tb11i3.ar123/7J2JEEtb11i3.ar123.7JKJ# 0 printf"89nThe ariable should not start with an alphabet.9n%nter the Correct ariable name :8#4 scanf"8DsDd8,tb11i3.ar,Etb11i3.alue#4 goto checF4 5 for"67146.i46II# 0 if"strcmp"tb11i3.ar,tb1163.ar#772# 0 printf"89nThe ariable already e*ists.%nter another ariable :9n8#4 scanf"8DsDd8,tb11i3.ar,Etb11i3.alue#4 goto checF4 5 5 5 printf"89n The table after creation is : 9n8#4 display"#4 5 oid insert"# 0 if"i/722# printf"89n Cannot insert. Table is full.9n8#4 else 0 nII4 printf"89n %nter the ariable and the alue : 8#4 scanf"8DsDd8,tb11n3.ar,Etb11n3.alue#4 checF: if"tb11i3.ar123/7J2JEEtb11i3.ar123.7JKJ# 0 printf"89nThe ariable should not start with an alphabet.9n%nter the Correct ariable name :8#4 scanf"8DsDd8,tb11i3.ar,Etb11i3.alue#4 goto checF4 5 for"67146.n46II# 0 if"strcmp"tb1163.ar,tb11i3.ar#772# 0 printf"89nThe ariable already e*ists.%nter another ariable :9n8#4 scanf"8DsDd8,tb11i3.ar,Etb11i3.alue#4 goto checF4 5 5 printf"89n The table after creation is : 9n8#4 display"#4 5 5 oid modify"# 0 char ariable11234 int result724 printf"89n %nter the ariable to be searched for : 8#4 scanf"8Ds8,ariable#4 result7search"ariable,n#4 if"result772# printf"89n The ariable doest not belong to the table.8#4 else 0 printf"89n The current alue of the ariable Ds is Dd.9n %nter the new ariable and its alue8,tb11result3.ar,tb11result3.alue#4 scanf"8DsDd8,tb11result3.ar,Etb11result3.alue#4 checF: if"tb11i3.ar123/7J2JEEtb11i3.ar123.7JKJ# 0 printf"89nThe ariable should not start with an alphabet.9n%nter the Correct ariable name :8#4 scanf"8DsDd8,tb11i3.ar,Etb11i3.alue#4 goto checF4 5 5 printf"89n The table after creation is : 9n8#4 display"#4 5 int search"char ariable13,int n# 0 int flag4 for"i714i.7n4iII# if"strcmp"tb11i3.ar,ariable#772# 0 flag714 breaF4 5 if"flag771# return i4 else return 24 5 oid display"# 0 printf"89nG':;'LB%9tG'B,%9n8#4 for"i714i.7n4iII# printf"89nDs9t9tDd8,tb11i3.ar,tb11i3.alue#4 getch"#4 5 OUTPUT.
1. C:%'T% 2. ;<S%:T $. )=D;>? &. S%':C@ (. D;SAB'? +. %C;T %nter your choice : 1 %nter the number of entries: $ %nter the ariable and the alue: <,)1 1 <,)2 2 <,)$ $ The table after creation is : G':;'LB% G'B,% <,)1 1 <,)2 2 <,)$ $ 1. C:%'T% 2. ;<S%:T $. )=D;>? &. S%':C@ (. D;SAB'? +. %C;T %nter your choice : 2 %nter the ariable and the alue : <,)1 12 The ariable already e*ists.%nter another ariable : 1<,) 12 The ariable should not start with an alphabet. %nter the Correct ariable name :<,)& & The table after insertion is : G':;'LB% G'B,% <,)1 1 <,)2 2 <,)$ $ <,)& & 1. C:%'T% 2. ;<S%:T $. )=D;>? &. S%':C@ (. D;SAB'? +. %C;T %nter your choice : $ %nter the ariable to be searched for : <,)$ The current alue of the ariable <,)$ is $. %nter the new ariable and its alue <,)$ $2 The table after modification is : G':;'LB% G'B,% <,)1 1 <,)2 2 <,)$ $2 <,)& & 1. C:%'T% 2. ;<S%:T $. )=D;>? &. S%':C@ (. D;SAB'? +. %C;T %nter your choice : & %nter the ariable to be searched for : <,)2 Gariable7<,)2 Galue72 Bocation72 1. C:%'T% 2. ;<S%:T $. )=D;>? &. S%':C@ (. D;SAB'? +. %C;T %nter your choice : + Res2/t. Thus the program to implement a symbol table with functions to create, insert, modify, search, and display, using C language was e*ecuted successfully. Ex- No- %ATE. IMPLEMENTATION OF PASS 1 OF A TWO PASS ASSEMBLER Aim. To implement a A'SS 1 of a two pass assembler, using C language. A/0orithm. Step 1: :ead the input line. Step 2: ChecF to see if the opcode field in the input line is MST':TN. 1. >ind if there is any operand field after ST':T4 initialiOe the B=CCT: to the operand alue. 2. =ther wise if there is no alue in the operand field the B=CCT: is set to Oero. Step $: Prite the line to the intermediate file. Step &: :epeat the following for the other lines in the program until the opcode field contains %<D directie. 1. ;f there is a symbol in the label field. i. ChecF the symbol table to see if has already been stored oer there. ;f so then it is a duplicate symbol, the error message should be displayed. ii. =ther wise the symbol is entered into the S?)T'L, along with the memory address in which it is stored. 2. ;f there is an opcode in the opcode field i. Search the =AT'L to see if the opcode is present, if so increment the location counter "B=CCT:# by three. ii. a# ;f the opcode is P=:D, increment the B=CCT: by three. b# ;f the opcode is L?T%, increment the B=CT: by one. c# ;f the opcode is :%SP, increment the B=CCT: by integer eQuialent of the operand alue R$. d# ;f the opcode is :%SL, increment the B=CCT: by the integer eQuialent of the operand alue. $ Prite each and eery line processed to the intermediate file along with their location counters. Step (: Calculate the length of the program by subtracting the starting address of the program from the final alue of the B=CCT: Step +: Close all the opened files and e*it. Pro0r1m. -include .stdio.h/ -include .conio.h/ -include .string.h/ -include .stdlib.h/ oid main"# 0 char opcode1123,mnemonic1123,operand1123,label1123,code11234 int locctr,start,length4 >;B% Rfp1,Rfp2,Rfp$,Rfp&4 clrscr"#4 fp17fopen"8input.dat8,8r8#4 fp27fopen"8symbtab.dat8,8w8#4 fp$7fopen"8out.dat8,8w8#4 fp&7fopen"8optab.dat8,8r8#4 fscanf"fp1,8DsDsDs8,label,opcode,operand#4 if"strcmp"opcode,8ST':T8#772# 0 start7atoi"operand#4 locctr7start4 fprintf"fp$,8Ds9tDs9tDs9n8,label,opcode,operand#4 fscanf"fp1,8DsDsDs8,label,opcode,operand#4 5 else locctr724 while"strcmp"opcode,8%<D8#H72# 0 fprintf"fp$,8Dd9t8,locctr#4 if"strcmp"label,8RR8#H72# fprintf"fp2,8Ds9tDd9n8,label,locctr#4 rewind"fp fscanf"fp&,8Ds8,mnemonic#4 while"strcmp"mnemonic,8%<D8#H72# 0 if"strcmp"opcode,mnemonic#772# 0 locctrI7$4 breaF4 5 fscanf"fp&,8Ds8,mnemonic#4 5 if"strcmp"opcode,8P=:D8#772# locctrI7$4 else if"strcmp"opcode,8:%SP8#772# locctrI7"$R"atoi"operand###4 else if"strcmp"opcode,8:%SL8#772# locctrI7"atoi"operand##4 else if"strcmp"opcode,8L?T%8#772# IIlocctr4 fprintf"fp$,8Ds9tDs9tDs9n8,label,opcode,operand#4 fscanf"fp1,8DsDsDs8,label,opcode,operand#4 5 fprintf"fp$,8Dd9tDs9tDs9tDs9n8,locctr,label,opcode,operand#4 length7locctrSstart4 printf"89n The length of the program is Dd8,length#4 fclose"fp1#4 fclose"fp2#4 fclose"fp$#4 fclose"fp getch"#4 5 INPUT INPUT-%AT )';< ST':T 2222 L%T;< BD' <,)1 RR ST' <,)2 RR BDC@ C@':1 RR STC@ C@':2 <,)1 P=:D ( <,)2 :%SP 1 C@':1 L?T% C!'! C@':2 :%SL 1 RR %<D L%T;< OPTAB-%AT 'DD 1U 'DD: K2 S,L 1C S,L: K& ),B 22 ),B: KU D;G 2& D;G: KC BD' 22 BDL +U BDC 2& BDC@ (2 ST' 2C STL VU STC 12 STC@ (& T;C 2C W $C WS,L &U :S,L &C W%X $2 WBT $U WTT $& ST':T R %<D R OUTPUT The length of the program is 22 OUT-%AT )';< ST':T 2222 2222 L%T;< BD' <,)1 222$ RR ST' <,)2 222+ RR BDC@ C@':1 222K RR STC@ C@':2 2212 <,)1 P=:D ( 221( <,)2 :%SP 1 221U C@':1 L?T% C!'! 221K C@':2 :%SL 1 2222 RR %<D L%T;< SYMBTAB-%AT L%T;< 2222 <,)1 2212 <,)2 221( C@':1 221U C@':2 221K Res2/t. Thus the program to implement a A'SS 1 of a two pass assembler, using C language was e*ecuted successfully. Ex- No- ! %ATE. IMPLEMENTATION OF PASS OF A TWO PASS ASSEMBLER Aim. To implement a A'SS 2 of a two pass assembler, using C language. A/0orithm. Step 1: :ead the first line from the intermediate file. Step 2: ChecF to see if the opcode field in the input line is MST':TN, if so then write the line onto the final output file. Step $: :epeat the following for the other lines in the intermediate file until the opcode field contains %<D directie. 1. ;f there is a symbol in the operand field, then the ob6ect code is assembled by combining the machine code eQuialent of the instruction with the symbol address. 2. ;f there is no symbol in the operand field, then the operand address is assigned as Oero and it is assembled with the machine code eQuialent of the instruction. $. ;f the opcode field is L?T% or P=:D or :%SL, then conert the constants in the operand filed to the ob6ect code. &. Prite the input line along with the ob6ect code onto the final output file. Step &: Close all the opened files and e*it. Pro0r1m. -include .stdio.h/ -include .conio.h/ -include .string.h/ -include .stdlib.h/ oid main"# 0 char symbol1223,opcode1223,mnemonic1223,operand1223,label1223,code1223,character,add1 223, ob6ectcode12234 int locctr,flag,flag1,loc4 >;B% Rfp1,Rfp2,Rfp$,Rfp&4 clrscr"#4 fp17fopen"8out.dat8,8r8#4 fp27fopen"8twoout.dat8,8w8#4 fp$7fopen"8optab.dat8,8r8#4 fp&7fopen"8symbtab.dat8,8r8#4 fscanf"fp1,8DsDsDs8,label,opcode,operand#4 if"strcmp"opcode,8ST':T8#772# 0 fprintf"fp2,89tDs9tDs9tDs9n8,label,opcode,operand#4 fscanf"fp1,8DdDsDsDs8,Elocctr,label,opcode,operand#4 5 while"strcmp"opcode,8%<D8#H72# 0 flag724 rewind"fp$#4 fscanf"fp$,8DsDs8,mnemonic,code#4 while"strcmp"mnemonic,8%<D8#H72# 0 if""strcmp"opcode,mnemonic#772#EE"strcmp"code,8R8#H72## 0 flag714 breaF4 5 fscanf"fp$,8DsDs8,mnemonic,code#4 5 if"flag771# 0 flag1724 rewind"fp while"Hfeof"fp&## 0 fscanf"fp&,8DsDd8,symbol,Eloc#4 if"strcmp"symbol,operand#772# 0 flag1714 breaF4 5 5 if"flag1771# 0 itoa"loc,add,12#4 strcpy"ob6ectcode,strcat"code,add##4 5 5 else if"strcmp"opcode,8L?T%8#772YYstrcmp"opcode,8P=:D8#772# 0 if"operand12377JCJYYoperand12377JCJ# 0 character7operand1234 itoa"character,add,1+#4 strcpy"ob6ectcode,add#4 5 else 0 itoa"atoi"operand#,add,12#4 strcpy"ob6ectcode,add#4 5 5 else strcpy"ob6ectcode,8928#4 fprintf"fp2,8Dd9tDs9tDs9tDs9tDs9n8,locctr,label,opcode,operand,ob6ectcode#4 fscanf"fp1,8DdDsDsDs8,Elocctr,label,opcode,operand#4 5 fprintf"fp2,89tDs9tDs9tDs9n8,label,opcode,operand#4 fclose"fp1#4 fclose"fp2#4 fclose"fp$#4 fclose"fp getch"#4 5 INPUT OUT-%AT )';< ST':T 2222 2222 L%T;< BD' <,)1 222$ RR ST' <,)2 222+ RR BDC@ C@':1 222K RR STC@ C@':2 2212 <,)1 P=:D ( 221( <,)2 :%SP 1 221U C@':1 L?T% C!'! 221K C@':2 :%SL 1 2222 RR %<D L%T;< SYMBTAB-%AT L%T;< 2222 <,)1 2212 <,)2 221( C@':1 221U C@':2 221K OPTAB-%AT 'DD 1U 'DD: K2 S,L 1C S,L: K& ),B 22 ),B: KU D;G 2& D;G: KC BD' 22 BDL +U BDC 2& BDC@ (2 ST' 2C STL VU STC 12 STC@ (& T;C 2C W $C WS,L &U :S,L &C W%X $2 WBT $U WTT $& ST':T R %<D R OUTPUT TWOOUT-%AT )';< ST':T 2222 2222 L%T;< BD' <,)1 222212 222$ RR ST' <,)2 2C221( 222+ RR BDC@ C@':1 (2221U 222K RR STC@ C@':2 (&221K 2212 <,)1 P=:D ( ( 221( <,)2 :%SP 1 221U C@':1 L?T% C!'! &1 221K C@':2 :%SL 1 RR %<D L%T;< Res2/t. Thus the program to implement a A'SS 2 of a two pass assembler, using C language was e*ecuted successfully. Ex- No- " %ATE. IMPLEMENTATION OF A SIN#LE PASS ASSEMBLER Aim. To implement a single pass "Boad and To# assembler, using C language. A/0orithm. Step 1: :ead the input line. Step 2: ChecF to see if the opcode field in the input line is MST':TN. 1. >ind if there is any operand field after ST':T4 initialiOe the B=CCT: to the operand alue. 2. =ther wise if there is no alue in the operand field the B=CCT: is set to Oero. Step $: Prite the line onto the output file. Step &: :epeat the following for the other lines in the input file until the opcode field contains %<D directie. 1. ;f there is a symbol in the label field. i. ChecF the symbol table to see if has already been stored and if it is marFed as undefined entry. ;f so then update the symbol table with the proper address and marF it as defined entry. ii. =ther wise the symbol is entered into the symbol table along with the memory address in which it is stored. 2. ;f there is an opcode in the opcode field i. Search the =AT'L to see if the opcode is present, if so increment the location counter "B=CCT:# by three. ii. a# ;f the opcode is P=:D, increment the B=CCT: by three and conert the constants in the operand field to the ob6ect code. b# ;f the opcode is L?T%, increment the B=CT: by one and conert the constants in the operand field to the ob6ect code. c# ;f the opcode is :%SP, increment the B=CCT: by integer eQuialent of the operand alue R$ and conert the constants in the operand field to the ob6ect code. d# ;f the opcode is :%SL, increment the B=CCT: by the integer eQuialent of the operand alue and conert the constants in the operand field to the ob6ect code. $. ;f there is a symbol in the operand field. i. ChecF the symbol table to see if has already been stored. ;f so, then assemble the ob6ect code by combining the machine code eQuialent of the instruction with the symbol address. ii. =ther wise the symbol is entered into the symbol table and it is marFed as undefined entry. &. ;f there is no symbol in the operand field, then operand address is assigned as Oero, and it is assembled with the machine code eQuialent of the instruction. (. Prite the input line along with the ob6ect code onto output file. Step (: Close all the opened files and e*it.
OUTPUT SYMTAB B==A1 222$ B==A2 222K <,)1 222+ <,)2 222K C@':1 221U C@':2 221K SPOUT-%AT )';< ST':T 2222 2 L%T;< WS,L B==A1 &U222$ RR WS,L B==A2 &U222K <,)1 P=:D ( ( <,)2 :%SP $ 2 C@':1 L?T% CJ'J +( C@':2 :%SL & 2 B==A1 BD' <,)1 22222+ RR ST' <,)2 2C222K B==A2 BDC@ C@':1 (2221U RR STC@ C@':2 (&221K RR %<D L%T;< 2 Res2/t. Thus the program to implement a single pass "Boad and To# assembler, using C language was e*ecuted successfully. Ex- No- $ %ATE. IMPLEMENTATION OF AN ABSOLUTE LOA%ER Aim. To implement an absolute loader, using C language. A/0orithm. Step 1: :ead the @eader record. Step 2: Gerify the Arogram name, length and starting address. Step $: :ead first Te*t record. Step &: :epeat the following process until an end record is encountered 1. Set B=C to starting address of the te*t record 2. ;f ob6ect code is in character form, then conert into internal he*adecimal representation. $. )oes ob6ect code to the specified location "B=C# in memory. &. ;ncrement B=C by three. (. :ead ne*t record from the input file. Step (: Wump to address specified in %nd record. Step +: Close all the opened files and e*it. Pro0r1m. -include .stdio.h/ -include .conio.h/ -include .string.h/ -include .stdlib.h/ struct ob6ectZcode 0 int locctr4 char byte1(34 54 struct ob6ectZcode code1(2234 oid main"# 0 char input11(34 int i,len,n72,count72,inc72,te*tloc,tlen72,tloc72,num72,loc4 >;B% Rfp1,Rfp24 clrscr"#4 fp17fopen"8loadin.dat8,8r8#4 fp27fopen"8loadout.dat8,8w8#4 rewind"fp1#4 rewind"fp2#4 fscanf"fp1,8Ds8,input#4 if"strcmp"input,8@8#772# 0 for"i724i.&4iII# 0 if"i771# fscanf"fp1,8D*8,Eloc#4 else fscanf"fp1,8Ds8,input#4 5 5 tloc7loc4 while"strcmp"input,8%8#H72# 0 if"strcmp"input,8T8#772# 0 fscanf"fp1,8D*8,Ete*tloc#4 for"i724i.te*tlocS"tlocItlen#4iII# 0 strcpy"code1inc3.byte,8**8#4 code1incII3.locctr7locII4 5 fscanf"fp1,8D*8,Etlen#4 tloc7te*tloc4 5 else 0 len7strlen"input#4 for"i724i.len4iII# 0 code1inc3.byte1numII37input1i34 if"num/1# 0 code1inc3.locctr7loc4 locII4 incII4 num724 5 5 5 fscanf"fp1,8Ds8,input#4 5 n724 i724 count724 fprintf"fp2,8D*9t8,code1i3.locctr#4 for"i724i.inc4iII# 0 fprintf"fp2,8Ds8,code1i3.byte#4 nII4 if"n/$# 0 fprintf"fp2,89t8#4 n724 countII4 5 if"count/$# 0 fprintf"fp2,89nD*9t8,code1iI13.locctr#4 count724 5 5 fclose"fp1#4 fclose"fp2#4 getch"#4 5 INPUT LOA%IN-%AT @ C=A? 222222 2212V' T 222222 1% 1&22$$ &U$2$K 1222$+ 2U22$2 $2221( &U$2+1 $C222$ 22222' 2C22$K 22222D T 22221% 1( 2C22$+ &U$2+1 1U22$$ &C2222 &(&>&+ 22222$ 122222 T 2222$K 1% 2&22$2 $222$2 %2$2(D $2$2$> DU$2(D 2U22$2 $2$2(V ($'2$K 2C$2(% $U$2$> T 2222(V 2' 1222$+ &C2222 >1 221222 T 2222V1 1K $&22$2 %2$2VK $2$2+& &>'2$K DC$2VK 2C22$+ $U$2+& &C2222 1( % 222222 OUTPUT LOA%OUT-%AT 2222 1&22$$&U $2$K1222 $+2U22$2 $2221(&U 2212 $2+1$C22 2$22222' 2C22$K22 222D2C22 2222 $+&U$2+1 1U22$$&C 2222&(&> &+22222$ 22$2 122222** ******** **2&22$2 $222$2%2 22&2 $2(D$2$2 $>DU$2(D 2U22$2$2 $2(V($'2 22(2 $K2C$2(% $U$2$>12 22$+&C22 22>12212 22+2 22****** ******** ******** ******** 22V2 **$&22$2 %2$2VK$2 $2+&&>'2 $KDC$2VK 22U2 2C22$+$U $2+&&C22 221( RESULT Thus the program to implement an absolute loader, using C language was e*ecuted successfully. AIM. To implement a C program for relocation loader. AL#ORIT3M. 1. %nter the new starting location to which the ob6ect code has to be relocated. 2. :ead the content of the input file as strings one at a time in an arrry NinputN. $. Transfer the string read in array MinputN into another array MoutputN, until MTN is encountered. &. )oe the consecutie ne*t three strings into array MoutputN. (. Conert the current string read which is the relocation bit associated with each te*t record to binary form. +. )aFe the necessary changes in the corresponding words of ob6ect code by adding the new starting address with the address part of the ob6ect code for which the corresponding relocation bit to set, and store the updated ob6ect code into the array MoutputN. Ex- No- & %ATE. IMPLEMENTATION OF A RELO'ATIN# LOA%ER V. )oe the ob6ect code for which the corresponding relocation bit is not set directly to the array MoutputN from the array MinputN without any change. U. :epeat step 2 to U until an end record is encountered. K. ;f ob6ect code is in character form conert form it to internal he*adecimal representation. 12. )oe ob6ect codes to specified locations in memory. 11. Prite the starting location counter alue of a blocF of ob6ect code, and the corresponding internal he*adecimal representations to the output file. PRO#RAM. -include.stdio.h/ -include.conio.h/ -include.string/ -include.stdlib.h/ struct ob6ectZcode 0 int locctr4 char add11234 5opcode1$2234 oid main"# 0 char in1122311+3,op1122311+3,bin1223,address1223,stloc11234 int len,bitmasF,loc,tlen72,tloc,te*tloc,i72,location,6,F,count72,start,n,num72,inc724 >;B% Rf1,Rf24 clrscr"#4 f17fopen"8lin.dat8,8r8#4 f27fopen"8lout.dat8,8w8#4 printf"8%nter the location where the program has to be loaded:8#4 scanf"8Ds8,stloc#4 start7atoi"stloc#4 location7start4 tloc7start4 fscanf"f1,8Ds8,in1i3#4 while"strcmp"in1i3,8T8#H72# 0 strcpy"op1i3,in1i3#4 iII4 fscanf"f1,8Ds8,in1i3#4 strcpy"op1i3,in1i3#4 5 itoa"start,op123,12#4 while"strcmp"in1i3,8%8#H72# 0 strcpy"op1i3,in1i3#4 if"strcmp"in1i3,8T8#772# 0 for"67246.$46II# 0 iII4 fscanf"f1,8Ds8,in1i3#4 strcpy"op1i3,in1i3#4 5 bitmasF7atoi"op1i3#4 itoa"bitmasF,bin,2#4 strcpy"op1i3,<,BB#4 te*tloc7atoi"op1iS23#4 te*tloc7te*tlocIstart4 itoa"te*tloc,op1iS23,12#4 for"n724n."te*tlocS"tlocItlen##4nII# 0 strcpy"opcode1inc3.add,8**8#4 opcode1incII3.locctr7locationII4 5 tlen7atoi"op1iS13#4 tloc7te*tloc4 F724 5 else 0 if"bin1F377J1J# 0 num724 len7strlen"op1i3#4 strcpy"address,<,BB#4 for"67246.len46II# 0 address1num37op1i31634 op1i31637J92J4 numII4 5 loc7atoi"address#4 loc7locIstart4 itoa"loc,address,12#4 strcat"op1i3,address#4 5 FII4 len7strlen"op1i3#4 num724 for"n724n.len4nII# 0 opcode1inc3.add1numII37op1i31n34 if"num/1# 0 opcode1incII3.locctr7locationII4 num724 5 5 5 iII4 fscanf"f1,8Ds8,in1i3#4 5 strcpy"op1i3,in1i3#4 iII4 fscanf"f1,8Ds8,in1i3#4 loc7atoi"in1i3#4 loc7locIstart4 strcpy"op1i3,itoa"loc,address,12##4 count724 i724 n724 fprintf"f2,8Dd9t8,opcode1n3.locctr#4 for"n724n.inc4nII# 0 fprintf"f2,8Ds8,opcode1n3.add#4 iII4 if"i/$# 0 fprintf"f2,89t8#4 i724 countII4 5 if"count/$# 0 fprintf"f2,89nDd9t8,opcode1nI13.locctr#4 count724 5 5 getch"#4 5 OUTPUT. %nter the location where the program has to be loaded: (222 LIN-%AT @ C=A? 222222 2212V$ T 222222 12 21( 1&22$$ &U12$K 1222$+ 2U22$2 $2221( &U12+1 $1122$ 2222$2 2112$$ 2222$$ T 222211 1K 2&( &122$+ &U12+1 $U22$$ &12222 &(&1K+ 12222$ 222222 % 222222 LOUT-%AT (222 1&(2$$&U +2$K12(2 $+2U(2$2 $2221(&U (21+ +2+1$112 2$2222$2 2112$$22 22$$**&1 (2$2 V2$+&U12 +1$U(2$$ &1V222&( &1K+12(2 (2&U 2$222222 RESULT. Thus the relocation loader were implemented and e*ecuted successfully. AIM. To implement a pass 1 of a direct linFing loader by using C program. AL#ORIT3M. 1. %nter the location where the program has to be loaded. 2. 'ssign the address got from the user as the first control section address. $. :ead the header record of the control section "i#>rom the details of the header read store the control section length in a ariable "ii#%nter the control section name with its address into the e*ternal symbol table. &. >or each symbol in the subseQuent D! records the symbol must be entered into the symbol table along with its address, added along with the corresponding control section address until an end record is reached. (. 'ssign the starting address of ne*t control section as the address of the current control section plus the length of the control section +. :epeat the process from step $ to step ( until there are no more input. Ex- No- ( %ATE. IMPLEMENTATION OF PASS 1 OF A %IRE'T LIN)IN# LOA%ER PRO#RAM. -include.stdio.h/ -include.conio.h/ -include.stdlib.h/ -define )'C 12 struct estab 0 char csect1123,symname11234 long int add4 int length4 5table1)'C34 oid main"# 0 >;B% Rf1,Rf24 char ip11234 long int i,count72,start,length,loc4 clrscr"#4 f17fopen"8lFin.dat8,8r8#4 f27fopen"8lFout.dat8,8w8#4 printf"8%nter the location where the pgm has to be loaded:8#4 scanf"8Dl*8,Estart#4 fprintf"f2,8CS%CT Tsymname Taddress Tlength9n8#4 rewind"f1#4 while"Hfeof"f1## 0 fscanf"f1,8Ds8,ip#4 if"strcmp"ip,8@8#772# 0 fscanf"f1,8Ds8,ip#4 strcpy"table1count3.csect,ip#4 strcpy"table1count3.symname,8928#4 fscanf"f1,8Ds8,ip#4 table1count3.add7atoi"ip#Istart4 fscanf"f1,8Ds8,ip#4 length7atoi"ip#4 table1countII3.length7atoi"ip#4 fscanf"f1,8Ds8,ip#4 5 if"strcmp"ip,8D8#772# 0 fscanf"f1,8DsDl*8,ip,Eloc#4 while"strcmp"ip,8:8#H72# 0 strcpy"table1count3.csect,8928#4 strcpy"table1count3.symname,ip#4 table1count3.add7locIstart4 table1countII3.length724 fscanf"f1,8DsDl*8,ip,Eloc#4 5 while"strcmp"ip,8T8#H72# fscanf"f1,8Ds8,ip#4 5 if"strcmp"ip,8T8#772# while"strcmp"ip,8%8#H72# fscanf"f1,8Ds8,ip#4 fscanf"f1,8Ds8,ip#4 start7startIlength4 5 for"i724i.count4iII# fprintf"f2,8Ds9tDs9tDl*9t Dd9n8,table1i3.csect,table1i3.symname,table1i3.add,table1i3.length#4 getch"#4 5 OUTPUT. L)IN-%AT @ A:=T' 222222 2222V2 D B;ST' 2222&2 %<D' 2222(& : B;STL %<DL B;STC %<DC T 222222 12 2$221D VV12222& 1(221& ) 22222& 2( IB;STL ) 2222(& 2+ IB;STC ) 2222(U 2+ I%<DC ) 2222+& 2+ IB;STL % 222222 L)OUT-%AT CS%CT Tsymname Taddress Tlength A:=T' $222 V2 B;ST' $2&2 2 %<D' $2(& 2 RESULT. Thus the pass 1 of a direct linFing loader were successfully implemented Ex- No- * %ATE. IMPLEMENTATION OF PASS OF A %IRE'T LIN)IN# LOA%ER AIM. To implement a pass2 of a direct linFing loader using C. AL#ORIT3M. 1. 'ssign the control section address in a ariable, CS'D:. 2. :ead the header record. "i#>rom the information aailable in the header record, store the control section length in a ariable. $. Do the following process until an end! record is reached. "i#;f the subseQuent records read is a te*t record T!, and if the ob6ect code is in character form conert it into machine representation ,and moe the ob6ect code from the record to the memory location control sections address plus the specified address in the te*t record. "ii#;f the subseQuent records read is modification record )! then search for the modifying symbol name in the e*ternal symbol table created by pass1 if it is found then add, or subtract the corresponding symbol address found with the alue 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. Arogram: -include.stdio.h/ -include.conio.h/ -include.string.h/ -include.stdlib.h/ struct ob6 0 char rec1223,sym1123,addr12234 5ob4 struct estab 0 char sym12234 int addr4 5 es4 oid main"# 0 >;B% Rf1,Rf24 int csaddr,maddr,cslth,addr4 clrscr"#4 f17fopen"8=LW.TCT8,8r8#4 f27fopen"8%ST'LB%.TCT8,8r8#4 fscanf"f2,8DsDd8,es.sym,Ees.addr#4 csaddr7es.addr4 printf"8)emoryaddr =b6ect code 9n8#4 while"Hfeof"f1## 0 fscanf"f1,8DsDsDs8,ob.rec,ob.sym,ob.addr#4 cslth7atoi"ob.addr#4 while"strcmp"ob.rec,8%8#H72# 0 int s4 fscanf"f1,8DsDsDs8,ob.rec,ob.sym,ob.addr#4 if"strcmp"ob.rec,8T8#772# 0 addr7csaddrIatoi"ob.sym#4 s7atoi"ob.addr#4 printf"8Dd9t Ds9n8,addr,ob.addr#4 5 if"strcmp"ob.rec,8)8#772# 0 maddr7csaddrIatoi"ob.sym#4 while"Hfeof"f2## 0 fscanf"f2,8DsDd8,es.sym,Ees.addr#4 if"strcmp"ob.addr,es.sym#772# 0 es.addr7es.addrIs4 printf"8Dd9t Dd9n8,maddr,es.addr#4 breaF4 5 5 rewind"f2#4 5 5 csaddrI 7cslth4 5 fcloseall"#4 getch"#4 5 INPUT FILE. OB4-T,T @ A:=T' 22+$ D B;ST' 22&2 T 22(& 2222 ) 22(& B;STL % 222$ <,BB @ A:=TL 22$2 D B;STL 22$2 T 22(2 2222 ) 22(2 B;ST' % 222$ <,BB ESTAB-T,T A:=T' &222 B;ST' &2&2 A:=TL &2+$ B;STL &2K$ OUTPUT. )emoryaddr =b6ect code &2(& 2222 &2(& &2K$ &11$ 2222 &11$ &2&2 Res2/t. Thus the pass 2 of a direct linFing loader were successfully implemented Ex- No- + %1te. IMPLEMENTATION OF A SIN#LE PASS MA'RO PRO'ESSOR Aim. To implement a single pass macro processor, using C language. A/0orithm. Step 1: Tet the line from the input file. Step 2: :epeat the following until the opcode field contains %<D directie. 1. ChecF if the opcode field contains )'C:= directie. ;f so, i. %nter the macro name into the <')T'L. ii. :ead the ne*t line. iii. :epeat the following until the opcode field contains )%<D directie. a. %nter the line into D%>T'L. b. :ead the ne*t line. i. )arF the pointers in the <')T'L to the beginning and end of the macro definition in D%>T'L. 2. ChecF if the opcode field contains )acro <ame. ;f so, i. :ead the corresponding macro definition from the D%>T'L. ii. Prite the macro definition onto the e*panded source file. $. =therwise, write the line onto the e*panded source file. Step $: Close all the opened files and e*it. Pro0r1m. -include .stdio.h/ -include .conio.h/ -include .string.h/ -include .stdlib.h/ oid main"# 0 int n,i,flag4 char ilab1223,iopd1223,oper1223,<')T'L122312234 >;B% Rfp1,Rfp2,RD%>T'L4 clrscr"#4 fp17fopen"8macin.dat8,8r8#4 fp27fopen"8macout.dat8,8w8#4 n724 rewind"fp1#4 fscanf"fp1,8DsDsDs8,ilab,iopd,oper#4 while"Hfeof"fp1## 0 if"strcmp"iopd,8)'C:=8#772# 0 strcpy"<')T'L1n3,ilab#4 D%>T'L7fopen"<')T'L1n3,8w8#4 fscanf"fp1,8DsDsDs8,ilab,iopd,oper#4 while"strcmp"iopd,8)%<D8#H72# 0 fprintf"D%>T'L,8Ds Ds Ds9n8,ilab,iopd,oper#4 fscanf"fp1,8DsDsDs8,ilab,iopd,oper#4 5 fclose"D%>T'L#4 nII4 5 else 0 flag724 for"i724i.n4iII# 0 if"strcmp"iopd,<')T'L1i3#772# 0 flag714 D%>T'L7fopen"<')T'L1i3,8r8#4 fscanf"D%>T'L,8DsDsDs8,ilab,iopd,oper#4 while"Hfeof"D%>T'L## 0 fprintf"fp2,8Ds Ds Ds9n8,ilab,iopd,oper#4 fscanf"D%>T'L,8DsDsDs8,ilab,iopd,oper#4 5 breaF4 5 5 if"flag772# fprintf"fp2,8Ds Ds Ds9n8,ilab,iopd,oper#4 5 fscanf"fp1,8DsDsDs8,ilab,iopd,oper#4 5 getch"#4 5 INPUT MA'IN-%AT )1 )'C:= RR RR BD' <1 RR 'DD <2 RR ST' <$ RR )%<D RR )2 )'C:= RR RR BD' <1 RR S,L <2 RR ST' <& RR )%<D RR )$ )'C:= RR RR BD' <1 RR ),B <2 RR ST' <( RR )%<D RR RR ST':T 1222 RR )$ RR RR )2 RR RR )1 RR RR %<D RR OUTPUT MA'OUT-%AT RR ST':T 1222 RR BD' <1 RR ),B <2 RR ST' <( RR BD' <1 RR S,L <2 RR ST' <& RR BD' <1 RR 'DD <2 RR ST' <$ RR %<D RR Res2/t. Thus the program to implement a single pass macro processor was e*ecuted Successfully. Ex- No- 10 %1te. IMPLEMENTATION OF A TWO PASS MA'RO PRO'ESSOR Aim. To implement a two pass macro processor, using C language. A/0orithm. Step 1: Tet the line from the input file. Step 2: :epeat the following until the opcode field contains %<D directie. 1. ChecF if the opcode field contains )'C:= directie. ;f so, i. %nter the macro name into the <')T'L. ii. :ead the ne*t line. iii. :epeat the following until the opcode field contains )%<D directie. a. %nter the line into D%>T'L. b. :ead the ne*t line. i. )arF the pointers in the <')T'L to the beginning and end of the macro definition in D%>T'L. 2. ChecF if the opcode field contains )acro <ame. ;f so, i. :ead the corresponding macro definition from the D%>T'L. ii. Prite the macro definition onto the e*panded source file. $. =therwise, write the line onto the e*panded source file. Step $: Close all the opened files and e*it. PRO#RAM. -include.stdio.h/ oid main"# 0 char a1123,b1123,c1123,a11123,b11123,c111234 >;B% Rfp1,Rfp2,Rfp$,Rfp(,Rfp&4 fp(7fopen"8nametab.t*t8,8w8#4 fp&7fopen"8e*p.t*t8,8w8#4 fp17fopen"8in11.t*t8,8r8#4 fp27fopen"8deftab.t*t8,8w8#4 fscanf"fp1,8Ds Ds Ds8,a,b,c#4 if"strcmp"b,8)'C:=8#772# 0 fprintf"fp(,8Ds9n8,a#4 5 fscanf"fp1,8Ds Ds Ds8,a,b,c#4 while"strcmp"b,8)%<D8#H72# 0 fprintf"fp2,8Ds Ds Ds9n8,a,b,c#4 fscanf"fp1,8Ds Ds Ds8,a,b,c#4 5 fprintf"fp2,8Ds Ds Ds9n8,a,b,c#4 fclose"fp2#4 fscanf"fp1,8Ds Ds Ds8,a,b,c#4 while"Hfeof"fp1## 0 fscanf"fp1,8Ds Ds Ds8,a,b,c#4 if"strcmp"b,8S,)8#772# 0 fp$7fopen"8deftab.t*t8,8r8#4 fscanf"fp$,8Ds Ds Ds8,a1,b1,c1#4 [[while"Hfeof"fp$## while"strcmp"b1,8)%<D8#H72# 0 fprintf"fp&,8Ds Ds Ds9n8,a1,b1,c1#4 fscanf"fp$,8Ds Ds Ds8,a1,b1,c1#4 5 5 fclose"fp$#4
[[printf"8hi Ds9n8,b#4 5 5 INPUT FILE. S,) )'C:= a1 S BD' -( S BDS a1 S 'DD: ',S S ST' :%S S )%<D S S S,) + S S,) U S S,) 1( S S,) 1&
OUTPUT. n1met15-txt. S,) exp-txt.6 S BD' -K S BDS a1 S 'DD: ',S S ST' :%S S BD' -( S BDS a1 S 'DD: ',S S ST' :%S S BD' -( S BDS a1 S 'DD: ',S S ST' :%S S BD' -( S BDS a1 S 'DD: ',S S ST' :%S 7eft15-txt. S BD' -( S BDS a1 S 'DD: ',S S ST' :%S S )%<D S Res2/t. Thus the program to implement two pass macro processor was e*ecuted successfully. Ex-no-11 %1te. IMPLEMENTATION OF A SIMPLE TE,T E%ITOR Aim. To write a c program to implement a simple te*t editor with features liFe insertion[deletion of a character, word, and sentence. A/0orithm . Step 1: Start Step 2: Design a te*t editor menu which contains the options liFe ;<S%:T, S%':C@ and D;SAB'?. Step $: ;f the option selected is ;<S%:T, then 1. Aroide a blanF screen for the user to type the te*t 2. Type the reQuired statement. %lse if the option is S%':C@ 1. Search the typed te*t 2. ;f the te*t is found, return the corresponding te*t Then type the reQuired te*t. $. %lse print string not found. Step &: ,sing the D;SAB'?"# function, display the te*t. Step (: Stop the e*ecution. Pro0r1m. -include.stdio.h/ -include.string.h/ -include.conio.h/ struct list 0 char te*t112234 5l112234 int i,n,*724 char s11223,s1112234 oid insert"#4 oid search"#4 oid display"#4 oid main"# 0 int ch4 clrscr"#4 do 0 printf"89t )%<,9n8#4 printf"81.;nsert 9n 2.Search9n $.Display9n &.%*it8#4 printf"89n %nter the opinion:8#4 scanf"8Dd8,Ech#4 switch"ch# 0 case 1: insert"#4 breaF4 case 2: search"#4 breaF4 case $: display"#4 breaF4 case &: e*it"1#4 55 while"ch.7 getch"#4 5 oid insert"# 0 printf"89n %nter the no of words in the te*t:8#4 scanf"8Dd8,En#4 printf"89n %nter the string:8#4 for"i714i.7n4iII# 0 scanf"8Ds8,l1i3.te*t#4 5 5 oid search"# 0 printf"8%nter the string to be searched:8#4 scanf"8Ds8,s#4 printf"8%nter the string to be inserted:8#4 scanf"8Ds8,s1#4 for"i714i.7n4iII# 0 *7strcmp"l1i3.te*t,s#4 if"*772# 0 strcpy"l1i3.te*t,s1#4 5 5 if"*H72# printf"8String not found9n8#4 5 oid display"# 0 printf"8The final string is:8#4 for"i714i.7n4iII# 0 printf"8Ds9t8,l1i3.te*t#4 5 getch"#4 5 OUTPUT: )%<, 1. ;nsert 2. Search $. Display &. %*it %nter the opinion: 1 %nter the no. of words in the te*t: $ %nter the string: @'; @%BB= L?% )%<, 1. ;nsert 2. Search $. Display &. %*it %nter the opinion: 2 %nter the string to be searched: L?% %nter the string to be inserted T@'<\S )%<, 1. ;nsert 2. Search $. Display &. %*it %nter the opinion: 2 %nter the string to be searched:L?% %nter the string to be inserted:P%BC=)% String not found )%<, 1. ;nsert 2. Search $. Display &. %*it %nter the opinion: $ The final string is: @'; @%BB= T@'<\S Res2/t. Thus, the c program to implement a simple te*t editor with features liFe insertion[deletion of a character, word, and sentence was implemented successfully.