Upload
prakash-palanisamy
View
223
Download
0
Embed Size (px)
Citation preview
8/4/2019 SS REC
1/69
System Software Laboratory
EX NO: IMPLEMENT A SYMBOL TABLE WITH
FUNCTIONS TO DATE: CREATE,
INSERT, MODIFY, SEARCH AND DISPLAY
AIM:
To write a program for implementation of searching and inserting in the
symbol table.
ALGORITHM:
1. start the program
2. open a source .c file which contains the assembly language program in
read mode3. open a sym .c file in write mode to save the symbol table to be
generated
4. the program for generating the symbol table iswritten
5. close the sym .c file
6. close the source .c file
7. generate the symbol table menu
8. generate the symbol to be searched print that the symbol is found in the
symbol table
9. read the symbol to be inserted and placed it in the symbol table and clear
for the existence afterwards
10. open sym .tab file for output of the program
11. the output is verified
12. stop the program
Department of Computer Science and
Engineering
8/4/2019 SS REC
2/69
PROGRAM FOR SYMBOL TABLE
#include
#include
#include
#include
void main()
{
FILE *f1,*f2;
char *str,*next,*c,*se,*s;
int count,f,t=0,choice,C;
clrscr();
f1=fopen("z:\source.c","r");
f2=fopen("z:\sym.c","w");
if(f1==NULL||f2==NULL)
{
printf("\n the file not found");
getch();
exit(0);
}
fprintf(f2,"lable name \t address");
while(!feof(f1))
{
scanf(f1,"%s",str);
if(strcmp(str,"ORG")==0)
8/4/2019 SS REC
3/69
System Software Laboratory
{
fscanf(f1,"%s",next);
count=atoi(next);
break;}
}
rewind(f1);
while(!feof(f1))
{
fscanf(f1,"%s",str);
c=strstr(str,":");
count++;
t=strcmp(c,":");
if(t==0)
{
fprintf(f2,"%s\t\t%d\n",str,count);
C=count;
} }
fclose(f1);
fclose(f2);
do
{
clrscr();
printf("SYMBOL TABLE\N");
printf("operations\n");
printf("1.SEARCH\n");
printf("2.INSERT\n");
printf("3.EXIT\n");
printf("ENTER YOUR CHOICE\n");
scanf("%d",choice);
Department of Computer Science and
Engineering
8/4/2019 SS REC
4/69
if(choice==1)
{
f=0;
printf("enter the lable to be searched:");scanf("%s",se);
//strcat(se,",");
f2=fopen("z:\sourc.c","r");
if(f2==NULL)
{
printf("DOES NOT");
}
while(!feof(f2))
{
fscanf(f2,"%s",str);
//printf("%s %s\n",str,se);
if(strcmp(str,se)==0)
{
printf("searching word %s found in the table \n",se);
f=1;
break;
}
else
{
f=0;
}
}
fclose(f2);
if(f==0)
printf("the searching word %s not found in the table",se);
getch();
8/4/2019 SS REC
5/69
System Software Laboratory
}
if(choice==2)
{
printf("enter trhe lable to be inserted:");scanf("%s",s);
f2=fopen("sym.tab","a");
fprintf(f2,"%s\t%d\n",s,C+1);
close(f2);
} }
while(choice
8/4/2019 SS REC
6/69
MOV M, B
OUTPUT:
SYMBOL TABLE OPERATION
1. SEARCH
2. INSERT
3. EXITENTER YPUR CHOICE: 1
Enter the label to search: COUNT
The searching word COUNT is found in the Table
SYMBOL TABLE OPERATION
1. SEARCH
2. INSERT
3. EXIT
ENTER YPUR CHOICE: 2
Enter the label to be inserted: INR
SYMBOL TABLE OPERATION
8/4/2019 SS REC
7/69
System Software Laboratory
1. SEARCH
2. INSERT
3. EXIT
ENTER YPUR CHOICE: 3
Z:\SYM.C
Label name address
LDA 2000
Z:\SYM.TAB
INR
Department of Computer Science and
Engineering
8/4/2019 SS REC
8/69
RESULT:
Thus the above program for symbol table was executed
successfully and the output was verified
EX NO: IMPLEMENT PASS ONE OF A TWO PASS
ASSEMBLERDATE:
AIM:
To write a program to implement pass one of a two pass assembler using
the concepts in c.
ALGORITHM:
1. start the program
2. create structure using OPTAB as structure name and create structure
variables
3. open the inp.dat file in read mode
8/4/2019 SS REC
9/69
System Software Laboratory
4. the inter .dat and symbol .dat is opened in the write mode
5. LOCCTR is initiated to the beginning address specified in the start
statement
6. after each source statement is processed the length of the assemblerinstruction
7. the labels are entered into symbol table along with assigned address
8. the intermediated file inter is created with contains the source statement
with its address error indicator which is the input to pass 1.
9. the output values are verified
10. Stop the program.
PROGRAM FOR PASS ONE OF A TWO PASS ASSEMBLER
#include
#include
#include
struct OPTAB{
char mne[10];
Department of Computer Science and
Engineering
8/4/2019 SS REC
10/69
char mcode[10];
};
struct OPTAB op[6]={{"LDA","5C"},{"LDX","04"},{"STA","0F"},
{"ADD","4D"},{"NAV","08"},{"AMM","55"}};
void main()
{
FILE *finp,*fint,*fsym;
char opc[10],oper[10],flag,label[10];
int i,locctr,curaddr;
clrscr();
finp=fopen("z:\INP.DAT","r");
fint=fopen("z:\INTER.DAT","w");
fsym=fopen("z:\SYMBOL.DAT","w");
fscanf(finp,"%s\t%s\n",opc,oper);
if (strcmp(opc,"START")==0)
locctr=atoi(oper);
else
locctr=0;
fscanf(finp,"%s\t%s\t%s\n",label,opc,oper);
while (strcmp(opc,"END")!=0)
{
flag='F';
curaddr=locctr;
if (strcmp(label,"NULL")!=0)
8/4/2019 SS REC
11/69
System Software Laboratory
fprintf(fsym,"%s\t%d\n",label,curaddr);
for (i=0;i
8/4/2019 SS REC
12/69
INP.DAT
START 1000
NULL LDX ZEROREPEAT LDA ALPHA
NULL ADD BETA
NULL STA GAMMA
NULL TIX DELTA
NULL JLT REPEAT
ZERO BYTE 0
ALPHA RESB 1
BETA RESW 1
GAMMA RESW 1
DELTA WORD 2
NULL END
8/4/2019 SS REC
13/69
System Software Laboratory
OUTPUT:
INTER.DAT
1000 NULL LDX ZERO1003 REPEAT LDA ALPHA
1006 NULL ADD BETA
1009 NULL STA GAMMA
1012 NULL TIX DELTA
1012 NULL JLT REPEAT
1012 ZERO BYTE 0
1013 ALPHA RESB 1
1014 BETA RESW 1
1017 GAMMA RESW 1
1020 DELTA WORD 2
NULL END
SYMBOL.DAT
REPEAT 1003
ZERO 1012
ALPHA 1013
BETA 1014
GAMMA 1017
DELTA 1020
Department of Computer Science and
Engineering
8/4/2019 SS REC
14/69
8/4/2019 SS REC
15/69
System Software Laboratory
RESULT:
Thus the above program for pass one of a two pass assembler
was executed successfully and the output was verified
EX NO: IMPLEMENT PASS TWO OF A TWO PASS
ASSEMBLER
DATE:
AIM:
To write a program to implement pass two of a two pass assembler using
the concepts in c.
ALGORITHM:
1. start the program
2. create global variables with required data type
3. open the inppass2.txt file in read mode
4. the psymou.txt and pass2op.txt is opened in the write mode
5. the beginning address specified in the start statement
6. after each source statement is processed the length of the assembler
instruction
7. the labels are entered into symbol table along with assigned address
8. the inter mediated file inter is created with contains the source statement
with its address error indicator which is the input to pass 2.
9. the output values are verified
10. Stop the program.
Department of Computer Science and
Engineering
8/4/2019 SS REC
16/69
PASS TWO OF A TWO PASS ASSEMBLER
#include
#include
int x,i,k=0,lin=99,il=0,kl=0,qq=0,lin1=100,linere[495],q1;
char s,ss[15],sym[15][15],ss1[15],ss2[15],ss3[15],val[100][10];
char oplin[15][15],opf[15][15],re[15][15],line[100][15],lit[100][15];
char rel[100][15],len[15],oopf[15][15];
char line1[15],sym1[15],rel1[15],lit1[15],len1[15],opc[25][25];
char dc1[15]="DC",ds1[15]="DS",qqq[15]="-",q12[10]="+";
int q3,q2;
void main()
{
FILE *fp3,*fp4,*tm;
fp3=fopen("z:\inppas2.txt","r");
fp4=fopen("z:\psymou.txt","r");
tm=fopen("z:\pass2op.txt","w");
clrscr();
rewind(fp3);
i=0;
while(!(feof(fp3)))
8/4/2019 SS REC
17/69
System Software Laboratory
{
strcpy(oplin[i],NULL);
strcpy(opc[i],NULL);
strcpy(re[i],NULL);strcpy(opf[i],NULL);
fscanf(fp3,"\t%s\t\t\t%s\t%s\t\t%s\n",oplin[i],opc[i],re[i],opf[i]);
rewind(fp4);
q2=strcmp(opf[i],qqq);
while(!(feof(fp4)))
{
fscanf(fp4,"\t%s\t\t%s\t%s\t%s\t%s\n",line1,sym1,lit1,len1,rel1);
if(strcmp(sym1,opf[i])==0)
{
strcpy(oopf[q1],line1);
q1++;
break;
}
}
if((q2==0))
{
oopf[q1][0]='-';
q1++;
}
fprintf(tm,"\t%s\t%s\t%s\t%s\n",oplin[i],opc[i],re[i],oopf[i]);
i++;
}
fclose(tm);
tm=fopen("z:\pass2op.txt","r");
printf("OUTPUT\n");
printf("====================================================
Department of Computer Science and
Engineering
8/4/2019 SS REC
18/69
=============\n");
printf("LOCATION COUNTER\tOPCODE\tREGISTER\tSYMBOL\n");
printf("====================================================
=============\n");while(!(feof(tm)))
{
fscanf(tm,"%s\t\t%s\t\t%s\t\t%s",oplin[i],opc[i],re[i],oopf[i]);
printf("%s\t\t%s\t\t%s\t\t%s\n",oplin[i],opc[i],re[i],oopf[i]);
}
getch();
}
INPUT: INPPASS2
100 09 - A
101 11 4 A102 04 - ONE
103 05 - RESULT
103 05 - TERM
105 04 - RESULT106 03 - TERM
107 05 - RESULT108 04 - TERM
109 01 - ONE
110 05 - TERM
111 13 4 AGAIN112 10 - RESULT
113 R#7 - -
114 R#1 - -115 R#7 - -
116 R#7 - -///////PSYMOU
106 AGAIN - 1 A
115 A - 1 A
116 ONE - 1 A117 TERM - 1 A
8/4/2019 SS REC
19/69
System Software Laboratory
118 RESULT - 1 A
OUTPUT:
100 09 - 115
101 11 - 115102 04 - 116103 05 - 118
103 05 - 117
105 04 - 118
106 03 - 117107 05 - 118
108 04 - 117
109 01 - 116110 05 - 117
111 13 4 106
112 10 - 118113 R#7 - -
114 R#1 - -
115 R#7 - -116 R#7 - -
Department of Computer Science and
Engineering
8/4/2019 SS REC
20/69
RESULT:
Thus the above program for pass two of a two pass assembler
was executed successfully and the output was verified
EX NO: IMPLEMENT A SINGLE PASS ASSEMBLERDATE:
AIM:
To implement a single pass assembler using the concepts in c
ALGORITHM:
1. Start the program
2. create the files for input and output
3. the source1.c file is read file i.e. input file
4. the ps.tab file is write mode file i.e. output file
5. then the base address initialized to the process
6. if the mnemonics are identified, the mnemonics are print in the op.tab
8/4/2019 SS REC
21/69
System Software Laboratory
files
7. the label values are stored in the sym.tab
8. then the label address are shown in the sym.tab
9. the opcode values are stored in the ps.tab10. the output values are verified
11. Stop the program.
PROGRAM FOR SINGLE PASS ASSEMBLER
#include
#include
void main()
{
FILE *f1,*f2,*f3;
char *next,*prev,*str,*c;
Department of Computer Science and
Engineering
8/4/2019 SS REC
22/69
int lcount,i;
clrscr();
f1=fopen("Z:\SOURCE1.c","r");
f2=fopen("Z:\PS.TAB","w");if(f1==NULL||f2==NULL)
{
printf("ERROR");
getch();
exit(0);
}
fprintf(f2,"\npseudotable\n");
while(!feof(f1))
{
fscanf(f1,"%s",str);
if(strcmp(str,"EQU")!=0)
{
strcpy(prev,str);
}
else
{
fscanf(f1,"%s",next);
fprintf(f2,"%s\t%s\t%s\t%s\n",str,prev,next);
}
if(strcmp(str,"ORG")==0)
{
strcpy(prev,str);
fscanf(f1,"%s",next);
fprintf(f2,"%s\t%s\t\n",prev,next);
break;
}
8/4/2019 SS REC
23/69
System Software Laboratory
}
fclose(f1);
fclose(f2);
f1=fopen("Z:\SOURCE1.C","r");f2=fopen("Z:\SY.TAB","w");
f3=fopen("Z:\OP.TAB","w");
fprintf(f2,"label name\t\taddress\n");
fprintf(f3,"Mnemonics\tOperand\n");
while(!feof(f1))
{
fscanf(f1,"%s",str);
if(strcmp(str,"ORG")==0)
{
fscanf(f1,"%s",next);
lcount=atoi(next);
break;
}
}
i=1;
while(!feof(f1))
{
fscanf(f1,"%s",str);
c=strstr(str,":");
lcount=lcount+i;
if(strcmp(c,":")==0)
fprintf(f2,"%s\t\t\t%d\n",str,lcount);
else
{
i=i+1;
if(i%2==0)
Department of Computer Science and
Engineering
8/4/2019 SS REC
24/69
fprintf(f3,"\n");
fprintf(f3,"%s\t\t",str);
} }
fclose(f1);fclose(f2);
fclose(f3);
f1=fopen("Z:\OP.TAB","r");
f2=fopen("Z:\PS.TAB","r");
f3=fopen("Z:\SY.TAB","r");
if(f1==NULL)
{
printf("as");
getch();
exit(0);
}
while(!(feof(f1)))
printf("%c",fgetc(f1));
while(!(feof(f2)))
printf("%c",fgetc(f2));
while(!(feof(f3)))
printf("%c",fgetc(f3));
fclose(f1);
fclose(f2);
fclose(f3);
getch();
}
INPUT: SOURCE
INBUF EQU 2050
8/4/2019 SS REC
25/69
System Software Laboratory
COUNTER EQU 06H
OUTBUF EQU 2010
ORG 2000H
XRA AMOV B,A
MVI C,COUNTER
LXI H,INBUF
NXTBYTE: ADD M
JNC NXTMEM
INR B
NXTMEM: INX H
DCR C
INZ NXTBYT
LXIH,OUTBUF
MOV M,A
INX H
MOV M,B
Department of Computer Science and
Engineering
8/4/2019 SS REC
26/69
OUTPUT:
Z:\OP.TAB
MNEMONICS OPERAND
XRA AMOV B,A
MVI C,COUNTER
LXI H,INBUFF
NXTBYTE: ADD M
JNC NXTMEM
INR B
NXTMEM: INX H
DCR C
INZ NXTBYT
LXI H, OUTBUF MOV
M,A INX
H MOV
M,B
Z:\PS.TAB
Pseudo Table
EQU INBUFF 2050
EQU COUNTER 06H
EQU OUTBUF 2010
EQU 2000H
Z:\SY.TAB
Label name Address
NXTBYTE: 2045
NXTMEM: 2129
8/4/2019 SS REC
27/69
System Software Laboratory
Department of Computer Science and
Engineering
8/4/2019 SS REC
28/69
RESULT:
Thus the above program for single pass assembler was
executed successfully and the output was verified
EX NO: IMPLEMENT A SINGLE PASS MACRO
PROCESSOR
DATE:
AIM:
To implement a single pass macro processor using the concepts in
cALGORITHM:
1. start the program
2. create the two file as macin.dat and outm.dat
3. the macin.dat file is read mode file i.e. input file
4. the outm.dat file is write mode file i.e. output file
5. print the no of macros in our input file
6. get the text file name for find the macro
7. if the file contains macro the macro will be separated using rewind
command
8. the output will be overwrite in outm.dat file
9. the output is verified
10. stop the program
8/4/2019 SS REC
29/69
System Software Laboratory
PROGRAM FOR SINGLE PASS MACRO PROCESSOR
#include
#include
#include
#include
void main()
{
char n1,n,c1,i;
char fn[10][10],ilab[20],iopd[20],m[20][3],oper[20],opd[20];
FILE *fp1,*fp2,*p[5];
clrscr();
n=0;
fp1=fopen("z:\macin.dat","r");
while(!feof(fp1))
{
fscanf(fp1,"%s%s",iopd,oper);
if(strcmp(iopd,"macro")==0)
n++;
}
printf("No.of Macros=%d\n",n);
Department of Computer Science and
Engineering
8/4/2019 SS REC
30/69
n1=n;
printf("\nEnter the text filename\n");
for(i=0;i
8/4/2019 SS REC
31/69
System Software Laboratory
while(!feof(fp1))
{
if(strcmp(iopd,"call")==0)
{for(i=0;i
8/4/2019 SS REC
32/69
INPUT:
OUTM.DAT
macrom1movea,b
mend---
macrom2
ldab
mend---
start1000
ldaa
callm1
callm2
adda,b
menda,b
OUTPUT:
MACIN..DAT
8/4/2019 SS REC
33/69
System Software Laboratory
macro m1
move a,b
mend ---
macro m2
lda b
mend ---
start 1000lda a
call m1
call m2
add a,b
mend
Department of Computer Science and
Engineering
8/4/2019 SS REC
34/69
RESULT:
Thus the above program for single pass macro processor wasexecuted successfully and the output was verified
8/4/2019 SS REC
35/69
System Software Laboratory
EX NO: IMPLEMENT AN ABSOLUTE LOADER
DATE:
AIM:
To implement a absolute loader using the concepts in c
ALGORITHM:
1. start the program
2. create the global variables
3. crate the files as source.c,tra.c,out.c
4. the source.c and tra.c files are read mode files i.e. input files
5. the out.c file is write mode file i.e. output file6. get the base address
7. then the opcodes are printed with its corresponding address values
8. the address values are generated by the base address value
9. the output values are verified
10. Stop the program
Department of Computer Science and
Engineering
8/4/2019 SS REC
36/69
PROGRAM FOR ABSOLUTE LOADER
#include
#include
int base,sadd2,sadd1,flag=0,type=0;char s1[15],s2[15],s3[15],s4[15],tr[20],tr1[20];void main()
{
FILE *f1,*f2,*f3;
clrscr();f1=fopen("z:\SOURCE.C","r");
f2=fopen("z:\TRA.C","r");
f3=fopen("z:\OUT.C","w");if(f2==NULL )
{
printf("ERROR");getch();
exit(0);
}printf("Enter the base address :\n");
scanf("%d",&base);
rewind(f1);
while(!feof(f1)){
fscanf(f1,"%s%s%s%s",s1,s2,s3,s4);
flag=0;
type=0;rewind(f2);
sadd1=atoi(s1);sadd2=sadd1+base;
if(strcmp(s2,"CALL")==0)
{
while(!feof(f2)){
fscanf(f2,"%s%s",tr,tr1);
if(strcmp(s3,tr)==0){
flag=1;strcpy(s2,"branch");strcpy(s3,tr1);
}
}if(flag==0)
8/4/2019 SS REC
37/69
System Software Laboratory
{type=1;
}
}if(type==0)
{fprintf(f3,"\n%10d%10s%10s%10s",sadd2,s2,s3,s4);
}
if(type==1)
{
fprintf(f3,"\n%10d%10s%10s%10s",sadd2,"UNDEFINED","","");
}
}printf("Program is executed\n");
getch();
}
Department of Computer Science and
Engineering
8/4/2019 SS REC
38/69
INPUT:
SOURCE.C
0 L 1, 12(0,15)8 CALL MANO -
12 CALL CATS -
14 CALL DOGS -18 CALL SHIP -
22 A 1, 13(0, 15)
OUTPUT:
Enter the BASE Address: 1000
Program is executed
Z:\OUT.C
1000 L 1, 12(0,15)1008 branch 500 -
1012 branch 1000 -1014 branch 2000 -
1018 UNDEFINED
1022 A 1, 13(0, 15)
1022 A 1, 13(0, 15)
Z:\TRA.C
MANO 500CATS 1000
DOGS 2000
8/4/2019 SS REC
39/69
System Software Laboratory
Department of Computer Science and
Engineering
8/4/2019 SS REC
40/69
RESULT:
Thus the above program for absolute loader was executed
successfully and the output was verified
EX NO: IMPLEMENT A RELOCATIONG LOADER
DATE:
AIM:
To implement a relocating loader using the concepts in c
ALGORITHM:
1. start the program
2. create the global variables3. crate the files as source.c,travect.c,out2.c
4. the source.c and travect.c files are read mode files i.e. input files
5. the out2.c file is write mode file i.e. output file
6. get the base address
7. then the opcodes are printed with its corresponding address values
8. the address values are generated by the base address value
9. the output values are verified
10. Stop the program
8/4/2019 SS REC
41/69
System Software Laboratory
PROGRAM FOR RELOCATING LOADER
#include
#include
#include
FILE*f1,*f2,*f3;
int base,sadd2,sadd1,flag=0,type=0,ad=0,l,a;
char s1[15],s2[15],s3[15],s4[15],tr[20],tr1[20];
void main()
{
clrscr();
f1=fopen("z:\SOURCE.c","r");
f2=fopen("z:\TRAVECT.c","r");
f3=fopen("z:\out2.c","w");
if(f1 == NULL || f2 == NULL)
{
printf("ERROR");
Department of Computer Science and
Engineering
8/4/2019 SS REC
42/69
getch();
exit(0);
}
printf("Enter the base address:\n");scanf("%d",&base);
rewind(f1);
while(!feof(f1))
{
fscanf(f1,"%s%s%s%s",s1,s2,s3,s4);
flag=0;
type=0;
rewind(f2);
sadd1=atoi(s1);
sadd2=sadd1+base;
if(strcmp(s2,"CALL")==0)
{
while(!feof(f2))
{
fscanf(f2,"%s%s",tr,tr1);
if(strcmp(s3,tr)==0)
{
flag=1;
strcpy(s2,"branch");
strcpy(s3,tr1);
}
}
if(flag==0)
{
type=1;
}
8/4/2019 SS REC
43/69
System Software Laboratory
}
if(type==0)
{
a=atoi(s3);if(a==500 || a==1000 || a==2000)
{
l = atoi(s3)+base;
fprintf(f3,"\n%10d%10s%10d%10s",sadd2,s2,l,s4);
}
else
fprintf(f3,"\n%10d%10s%10d%10s",sadd2,s2,a,s4);
}
if(type==1)
{
fprintf(f3,"\n%10d%10s%10d%10s",sadd2,"UNDEFINED","","");
}
}
printf("Program is executed\n");
fclose(f1);
fclose(f2);
fclose(f3);
getch();
}
Department of Computer Science and
Engineering
8/4/2019 SS REC
44/69
INPUT:
Z:\source.c
8 CALL MANO -12 CALL CATS -
14 CALL DOGS -
18 CALL SHIP -22 A 1, 13(0, 15)
Z:\TRA.c
MANO 500
CATS 1000DOGS 2000
8/4/2019 SS REC
45/69
System Software Laboratory
Enter the BASE Address: 1000
Program is executed
OUTPUT:
1000 L 1 12(0, 15)
1008 branch 1500 -
1012 branch 2000 -
1014 branch 3000 -1018 UNDEFINED 338
1022 A 1 13(0, 15)
1022 A 1 13(0, 15)
Department of Computer Science and
Engineering
8/4/2019 SS REC
46/69
RESULT:
Thus the above program for relocating loader was executed
successfully and the output was verified
EX NO: IMPLEMENT PASS ONE OF A DIRECT LINKING
LOADERDATE:
AIM:
8/4/2019 SS REC
47/69
System Software Laboratory
To implement a pass one of a direct linking loader using the concepts in c
ALGORITHM:
1. start the program2. create the files iss.dat and estab.dat
3. the iss.dat file as input file i.e read mode file
4. the estab.dat file as output file i.e. write mode file
5. get the base(starting) address
6. select the mnemonics from the iss.dat file
7. then the address is automatically generated by the loader
8. if the labels are presented, the object code is generated
9. .the output values are verified
10. Stop the program
/*PROGRAM FOR PASS ONE OF A DIRECT LINKING LOADER*/
Department of Computer Science and
Engineering
8/4/2019 SS REC
48/69
8/4/2019 SS REC
49/69
System Software Laboratory
if(strcmp(rtype,"D")==0)
{
i=0;
while(str1[i]!='\0'){
k=i+5;
for(j=0;i
8/4/2019 SS REC
50/69
8/4/2019 SS REC
51/69
System Software Laboratory
Department of Computer Science and
Engineering
8/4/2019 SS REC
52/69
RESULT:Thus the above program for pass one of a direct linking loader
was executed successfully and the output was verified
EX NO: IMPLEMENT PASS TWO OF A DIRECT LINKING
LOADER
DATE:
AIM:
To implement a pass one of a direct linking loader using the concepts in c
ALGORITHM:
1. start the program
2. create the files iss.dat,estab.dat and load1.dat
3. the iss.dat file as input file i.e read mode file
4. the estab.dat and load1.dat file as output file i.e. write mode file
5. get the base(starting) address
6. select the mnemonics from the iss.dat file
7. then the address is automatically generated by the loader
8. the byte values for each instruction is generated by the loader
9. if the labels are presented, the object code is generated
10. .the output values are verified
11. Stop the program
8/4/2019 SS REC
53/69
System Software Laboratory
PROGRAM FOR PASS 2 OF A DIRECT LINKING LOADER
#include
#include
#include
#include
void main()
{
FILE *fp1,*fp2,*fp3;
char oper,d1[10],cslth[10]="",obj[10],str1[80];
char str3[20],len[3],str2[10],maddr[10],rtype[3];
char sym[10],taddr[10];
int laddr,progaddr,l,i,m,addr,csaddr,j,k,curaddr;
long int d;
fp1=fopen("z:\iss.dat","r");
fp2=fopen("z:\estab.dat","r");
fp3=fopen("z:\load1.dat","w+");
clrscr();
printf("\nEnter program address:");
Department of Computer Science and
Engineering
8/4/2019 SS REC
54/69
scanf("%d",&progaddr);
csaddr=progaddr;
curaddr=0;
while(!feof(fp1)){
fscanf(fp1,"%c",rtype);
rtype[1]='\0';
fscanf(fp1,"%[^\n]\n",str1);
if(strcmp(rtype,"H")==0)
{
for(i=10,j=0;i
8/4/2019 SS REC
55/69
System Software Laboratory
{
sym[j]=str1[i];
i++;
j++;}
sym[j]='\0';
fprintf(fp3,"%d\t%s\n",curaddr,sym);
curaddr+=1;
}
csaddr=progaddr+atoi(cslth);
}
}
rewind(fp1);
csaddr=progaddr;
while(!feof(fp1))
{
fscanf(fp1,"%c",rtype);
rtype[1]='\0';
fscanf(fp1,"%[^\n]\n",str1);
if(strcmp(rtype,"M")==0)
{
for(i=0,j=0;i
8/4/2019 SS REC
56/69
while(!feof(fp2))
{
fscanf(fp2,"%s",str2);
if(strcmp(str2,sym)==0){
fscanf(fp2,"\t%s",str1);
addr=atoi(str1);
}
fscanf(fp2,"\n",str2);
}
rewind(fp3);
while(!feof(fp3))
{
fscanf(fp3,"%d\t%s\n",&curaddr,str3);
if(curaddr==m)
{
strcpy(obj," ");
for(i=1;i
8/4/2019 SS REC
57/69
System Software Laboratory
strcmp(sym,"");
j=0;
for(k=0;k
8/4/2019 SS REC
58/69
ISS.DAT
HPROGA 000000000063
DLISTA 000040ENDA 000054RLISTB ENDB LISTC ENDC
T0000200A03201D77100004050014
M00002405+LISTB
E000020
HPROGB 00000000007F
DLISTB 000060ENDB 000070
RLISTA ENDA LISTC ENDC
T0000360B0310000077202705100000
E
OUTPUT:
LOAD1.DAT
1020 03
1021 20
1022 1D
1023 77
1024 10
1025 00
8/4/2019 SS REC
59/69
System Software Laboratory
1026 04
1027 05
1028 00
1029 141036 03
1037 10
1038 00
1039 00
1040 77
1041 20
1042 27
1043 05
1044 10
1045 00
1046 00
Department of Computer Science and
Engineering
8/4/2019 SS REC
60/69
RESULT:
Thus the above program for pass two of a direct linking loader
was executed successfully and the output was verified
EX NO: IMPLEMENT A SIMPLE TEXT EDITOR WITHFEATURES DATE: LIKE INSERTION/DELETION OF A
CHARACTER,
WORD AND SENTENCE
8/4/2019 SS REC
61/69
System Software Laboratory
AIM:
To implement a simple text editor with features like insertion/deletion of
a
Character, word and sentence
ALGORITHM:
1. Start the program
2. get your option( choice )
3. if your choice is 1 means the new file is executed
4. if your option is 2 means the opening a file is executed. The open path is
depend on the user.
5. if your open path is wrong means the message enter correct path will
be displayed
6. if your option is 3 means the file is saving. The saving path will be set by
the user
7. if your file name is already exists means the message the file is already
exists. So please choose another file is executed
8. if your option is 4 means the file will be deleted immediately
9. if your option is 5 means your program will terminated immediately
10. the output values are verified
11. Stop the program
Department of Computer Science and
Engineering
8/4/2019 SS REC
62/69
/* PROGRAM FOR TEXT EDITOR*/
#include#include
#include
void main()
{
FILE *fn,*fd;
char line[20][20],fname[20],str[30],op;
int i,j,k,len=0,ch=1,sn,n;
clrscr();
while(ch!=0)
{
printf("\n\nMENU\n\n");
printf("\n1.NEW\n2.OPEN\n3.SAVE\n4.DELETE\n5.EXIT\n\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("Enter the file content and at last type EDN\n");
i=0;
fflush(stdin);
gets(line[i]);
strcat(line[i],"\n");
while(strcmp(line[i],"end\n")!=0)
{
gets(line[++i]);
strcat(line[i],"\n");
8/4/2019 SS REC
63/69
System Software Laboratory
}
--i;
break;
case 2:printf("Enter the file name to open\n");
scanf("%s",fname);
if(searchpath(fname))
{
fn=fopen(fname,"r+");
while(1)
{
ch=fgetc(fn);
if(ch==EOF)
break;
else
{
if(ch=='\\')
printf("\n");
printf("%c",ch);
}
}
getch();
fclose(fn);
}
else
{
printf("enter a valid file name\n");
getch();
}
break;
Department of Computer Science and
Engineering
8/4/2019 SS REC
64/69
case 3:
printf("Enter the file name\n");
scanf("%s",fname);
if(searchpath(fname)){
printf("This file already exist.Do you want to
overwrite Y/N");
fflush(stdin);
scanf("%c",&op);
if(op=='Y' || op=='y')
printf("");
else
break;
}
fn=fopen(fname,"a+");
j=0;
while(j
8/4/2019 SS REC
65/69
System Software Laboratory
case 4:
printf("Enter the file to be deleted\n");
scanf("%s",fname);
unlink(fname);break;
case 5:
exit(0);
break;
}
getch();
}
}
Department of Computer Science and
Engineering
8/4/2019 SS REC
66/69
OUTPUT:
MENU
1. NEW
2. OPEN
3. SAVE
4. DELETE
5. EXIT
2
Enter the file to open: fn.txt
MENU
1. NEW
2. OPEN
3. SAVE
4. DELETE
5. EXIT
3
Enter the file name:
f1.txt
8/4/2019 SS REC
67/69
System Software Laboratory
MENU
1. NEW
2. OPEN
3. SAVE4. DELETE
5. EXIT
4
Enter the file to delete:
Fn.txt
MENU
1. NEW
2. OPEN
3. SAVE
4. DELETE
5. EXIT
1
Enter the file content at last type EDN
Hi I am James EDN
MENU
1. NEW
2. OPEN
3. SAVE
4. DELETE
5. EXIT
3
Enter the file name:
fd.txt
Department of Computer Science and
Engineering
8/4/2019 SS REC
68/69
MENU
1. NEW
2. OPEN
3. SAVE4. DELETE
5. EXIT
5
8/4/2019 SS REC
69/69
System Software Laboratory
RESULT:
Thus the above program for text editor was executed
successfully and the output was verified