You are on page 1of 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 mode 3. 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

PROGRAM FOR SYMBOL TABLE #include<stdio.h> #include<conio.h> #include<string.h> #include<stdlib.h> 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)

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

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();

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<3); } INPUT: SOURCE INBUF EQU 2050 COUNTER EQU 06H OUTBUF EQU 2010 ORG 2000H XRA A MOV 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
Department of Computer Science and Engineering

MOV M, B

OUTPUT: SYMBOL TABLE OPERATION 1. SEARCH 2. INSERT 3. EXIT ENTER 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

System Software Laboratory

1. SEARCH 2. INSERT 3. EXIT ENTER YPUR CHOICE: 3

Z:\SYM.C Label name LDA Z:\SYM.TAB INR address 2000

Department of Computer Science and Engineering

RESULT: Thus the above program for symbol table was executed successfully and the output was verified

EX NO: ASSEMBLER DATE: AIM:

IMPLEMENT PASS ONE OF A TWO PASS

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

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 assembler instruction 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<stdio.h> #include<string.h> #include<conio.h> struct OPTAB{ char mne[10];
Department of Computer Science and Engineering

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)

System Software Laboratory

fprintf(fsym,"%s\t%d\n",label,curaddr); for (i=0;i<=5;i++) { if (strcmp(opc,op[i].mne)==0) flag='T'; } if (flag=='T') locctr+=3; else if (strcmp(opc,"RESW")==0) locctr+=3*atoi(oper); else if (strcmp(opc,"RESB")==0) locctr+=atoi(oper); else if (strcmp(opc,"BYTE")==0) locctr+=strlen(oper); else if (strcmp(opc,"WORD")==0) locctr+=3; else printf("%d\t%s\t%s\t%s\t INVALID\n",curaddr,label,opc,oper); fprintf(fint,"%d\t%s\t%s\t%s\n",curaddr,label,opc,oper); fscanf(finp,"%s\t%s\t%s\n",label,opc,oper); } fprintf(fint,"\tNULL\tEND"); printf("Program is executed successfully"); getch(); }

INPUT:
Department of Computer Science and Engineering

INP.DAT START REPEAT NULL STA NULL TIX NULL JLT ALPHA GAMMA DELTA NULL END 1000 LDA ALPHA GAMMA DELTA REPEAT RESB 1 RESW 1 WORD 2 NULL LDX ZERO NULL ADD BETA

ZERO BYTE 0 BETA RESW 1

System Software Laboratory

OUTPUT: INTER.DAT 1000 1003 1006 1009 1012 1012 1012 1013 1014 1017 1020 NULL LDX ZERO REPEAT NULL STA NULL TIX NULL JLT ALPHA GAMMA DELTA NULL END LDA ALPHA GAMMA DELTA REPEAT RESB 1 RESW 1 WORD 2 NULL ADD BETA

ZERO BYTE 0 BETA RESW 1

SYMBOL.DAT REPEAT ZERO 1012 ALPHA BETA 1014 GAMMA DELTA 1017 1020 1013 1003

Department of Computer Science and Engineering

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: ASSEMBLER DATE:

IMPLEMENT PASS TWO OF A TWO PASS

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

PASS TWO OF A TWO PASS ASSEMBLER #include<stdio.h> #include<conio.h> 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)))

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

=============\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 A 102 04 ONE 103 05 RESULT 103 05 TERM 105 04 RESULT 106 03 TERM 107 05 RESULT 108 04 TERM 109 01 ONE 110 05 TERM 111 13 4 AGAIN 112 10 RESULT 113 R#7 114 R#1 115 R#7 116 R#7 ///////PSYMOU 106 AGAIN 115 A 1 116 ONE 1 117 TERM 1

1 A A A

System Software Laboratory

118

RESULT

OUTPUT: 100 101 102 103 103 105 106 107 108 109 110 111 112 113 114 115 116

09 11 04 05 05 04 03 05 04 01 05 13 10 R#7 R#1 R#7 R#7

4 -

115 115 116 118 117 118 117 118 117 116 117 106 118 -

Department of Computer Science and Engineering

RESULT: Thus the above program for pass two of a two pass assembler was executed successfully and the output was verified
EX NO: DATE: 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 IMPLEMENT A SINGLE PASS ASSEMBLER

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.tab 10. the output values are verified 11. Stop the program.

PROGRAM FOR SINGLE PASS ASSEMBLER #include<stdio.h> #include<conio.h> void main() { FILE *f1,*f2,*f3; char *next,*prev,*str,*c;
Department of Computer Science and Engineering

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; }

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

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

System Software Laboratory

COUNTER EQU 06H OUTBUF EQU 2010 ORG 2000H XRA A MOV 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

OUTPUT: Z:\OP.TAB MNEMONICS XRA MOV MVI LXI NXTBYTE: ADD JNC INR NXTMEM: INX DCR INZ M,A H M,B Z:\PS.TAB Pseudo Table EQU INBUFF EQU COUNTER EQU OUTBUF EQU 2000H Z:\SY.TAB Label name NXTBYTE: NXTMEM: Address 2045 2129 2050 06H 2010 OPERAND A B,A C,COUNTER H,INBUFF M NXTMEM B H C NXTBYT MOV INX MOV

LXI H, OUTBUF

System Software Laboratory

Department of Computer Science and Engineering

RESULT: Thus the above program for single pass assembler was executed successfully and the output was verified
EX NO: PROCESSOR DATE: AIM: To implement a single pass macro processor using the concepts in c ALGORITHM: 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 IMPLEMENT A SINGLE PASS MACRO

System Software Laboratory

PROGRAM FOR SINGLE PASS MACRO PROCESSOR #include<stdio.h> #include<conio.h> #include<string.h> #include<stdlib.h> 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

n1=n; printf("\nEnter the text filename\n"); for(i=0;i<n;i++) { scanf("%s",fn[i]); p[i]=fopen(fn[i],"w"); } n=0; rewind(fp1); while(!feof(fp1)) { fscanf(fp1,"%s%s",iopd,oper); if(strcmp(iopd,"macro")==0) { strcpy(m[n],oper); fscanf(fp1,"%s%s",iopd,oper); while(strcmp(iopd,"mend")==0) { fprintf(p[n],"%s%s\n",iopd,oper); fscanf(fp1,"%s%s",iopd,oper); } fclose(p[n]); n++; } } for(i=0;i<n1;i++) p[i]=fopen(fn[i],"r"); fp2=fopen("z:outm.dat","w"); rewind(fp1); fscanf(fp1,"%s%s",iopd,oper);

System Software Laboratory

while(!feof(fp1)) { if(strcmp(iopd,"call")==0) { for(i=0;i<n1;i++) { if(strcmp(m[i],oper)==0) { rewind(p[i]); fscanf(p[i],"%s%s",iopd,oper); while(!feof(p[i])) { fprintf(fp2,"%s%s\n",iopd,oper); c1=1; fscanf(p[i],"%s%s",iopd,oper); } break; } } } if(c1!=1) fprintf(fp2,"%s%s\n",iopd,oper); c1=0; fscanf(fp1,"%s%s",iopd,oper); } fprintf(fp2,"%s%s\n",iopd,oper); }

Department of Computer Science and Engineering

INPUT: OUTM.DAT
macrom1 movea,b mend--macrom2 ldab mend--start1000 ldaa callm1 callm2 adda,b menda,b

OUTPUT: MACIN..DAT

System Software Laboratory

macro m1 move a,b mend --macro m2 lda b mend --start 1000 lda a call m1 call m2 add a,b mend

Department of Computer Science and Engineering

RESULT: Thus the above program for single pass macro processor was executed successfully and the output was verified

System Software Laboratory

EX NO: DATE:

IMPLEMENT AN ABSOLUTE LOADER

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 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

Department of Computer Science and Engineering

PROGRAM FOR ABSOLUTE LOADER #include<stdio.h> #include<conio.h> 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)

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

INPUT: SOURCE.C 0 8 12 14 18 22 L 1, 12(0,15) CALL MANO CALL CATS CALL DOGS CALL SHIP 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 CATS DOGS 500 1000 2000

System Software Laboratory

Department of Computer Science and Engineering

RESULT: Thus the above program for absolute loader was executed successfully and the output was verified

EX NO: DATE: AIM:

IMPLEMENT A RELOCATIONG LOADER

To implement a relocating loader using the concepts in c ALGORITHM: 1. start the program 2. create the global variables 3. 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

System Software Laboratory

PROGRAM FOR RELOCATING LOADER #include<stdio.h> #include<string.h> #include<conio.h> 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

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; }

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

INPUT: Z:\source.c 8 12 14 18 22 CALL MANO CALL CATS CALL DOGS CALL SHIP A 1, 13(0, 15)

Z:\TRA.c MANO CATS DOGS 500 1000 2000

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

RESULT: Thus the above program for relocating loader was executed successfully and the output was verified

EX NO: LOADER DATE:

IMPLEMENT PASS ONE OF A DIRECT LINKING

AIM:

System Software Laboratory

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 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

#include<stdio.h> #include<conio.h> #include<string.h> void main() { char cslth[10],str1[80],csname[10],rtype[3],sym[10],radd[10]; int i,j,k,csaddr,saddr; FILE *fp1,*fp2; fp1=fopen("z:\I55.DAT","r"); fp2=fopen("z:\ESTAB.DAT","w"); clrscr(); strcpy(rtype,"H"); printf("Enter the starting address:"); scanf("%d",&saddr); csaddr=saddr; while(!feof(fp1)) { fscanf(fp1,"%[^\n]",str1); for(i=1,j=0;i<=6;i++,j++) csname[j]=str1[i]; csname[j]='\0'; for(i=13,j=0;i<=18;i++,j++) cslth[j]=str1[i]; cslth[j]='\0'; fprintf(fp2,"%s\t%d\t%s\n",csname,csaddr,cslth); while(strcmp(rtype,"E")!=0) { fscanf(fp1,"\n%c",rtype); rtype[1]='\0'; fscanf(fp1,"%[^\n]\n",str1);

System Software Laboratory

if(strcmp(rtype,"D")==0) { i=0; while(str1[i]!='\0') { k=i+5; for(j=0;i<=k;i++,j++) sym[j]=str1[i]; sym[j]='\0'; k=i+5; for(j=0;i<=k;i++,j++) radd[j]=str1[i]; radd[j]='\0'; fprintf(fp2,"%s\t%d\n",sym,csaddr+atoi(radd)); } } } csaddr=csaddr+atoi(cslth); strcpy(rtype,"H"); } getch(); }

Department of Computer Science and Engineering

INPUT: Z:\I55.DAT HPROGA 000000000063 DLISTA 000040 ENDA 000054 RLISTB ENDB LISTC ENDC T0000200A03201D77100004050014 M 00002405 +LISTB E 000020 HPROGB 00000000007F DLISTB 000060 ENDB 000070 RLISTA ENDA LISTC ENDC T0000360B0310000077202705100000 E OUTPUT: Z:\ESTAB.DAT PROGA LISTA 1040 ENDA PROGB LISTB ENDB 1000 1054 1063 1123 1133 000063 00007F

System Software Laboratory

Department of Computer Science and Engineering

RESULT: Thus the above program for pass one of a direct linking loader was executed successfully and the output was verified

EX NO: LOADER DATE: AIM:

IMPLEMENT PASS TWO OF A DIRECT LINKING

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

System Software Laboratory

PROGRAM FOR PASS 2 OF A DIRECT LINKING LOADER #include<stdio.h> #include<conio.h> #include<string.h> #include<stdlib.h> 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

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<=10;i++,j++) cslth[j]=str1[i]; cslth[j]='\0'; } else if(strcmp(rtype,"T")==0) { for(i=0,j=0;i<=5;i++,j++) taddr[j]=str1[i]; taddr[j]='\0'; curaddr=csaddr+atoi(taddr); l=i+2; j=0; for(;i<l;i++,j++) len[j]=str1[i]; len[j]='\0'; while(str1[i]!='\0') { j=0; strcpy(sym,""); for(k=0;k<2;k++)

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<=5;i++,j++) maddr[j]=str1[i]; maddr[j]='\0'; m=csaddr+atoi(maddr); oper=str1[i+2]; for(i=i+3,j=0;str1[i]!='\0';i++,j++) sym[j]=str1[i]; sym[j]='\0'; rewind(fp2);
Department of Computer Science and Engineering

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<=3;i++) { strcat(obj,str3); fscanf(fp3,"%d\t%s\n",&curaddr,str3); } if(oper=='+') d=atol(obj)+addr; else d=atol(obj)+addr; ltoa(d,d1,10); i=0; while(d1[i]!='\0') {

System Software Laboratory

strcmp(sym,""); j=0; for(k=0;k<2;k++) { sym[j]=d1[i]; i++; j++; } sym[j]='\0'; printf("%d\t%s\n",m,sym); m++; } printf("%d\t%s\n",curaddr,str3); } else { printf("%d\t%s\n",curaddr,str3); } } } } } INPUT: ESTAB.DAT PROGA LISTA ENDA 0 PROGB LISTB ENDB 0 14 1063
Department of Computer Science and Engineering

1000 1040 1054 1063 1123 1133

000063

00007F

ISS.DAT HPROGA 000000000063 DLISTA 000040ENDA 000054 RLISTB ENDB LISTC ENDC T0000200A03201D77100004050014 M00002405+LISTB E000020 HPROGB 00000000007F DLISTB 000060ENDB 000070 RLISTA ENDA LISTC ENDC T0000360B0310000077202705100000 E

OUTPUT: LOAD1.DAT 1020 1021 1022 1023 1024 1025 03 20 1D 77 10 00

System Software Laboratory

1026 1027 1028 1029 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046

04 05 00 14 03 10 00 00 77 20 27 05 10 00 00

Department of Computer Science and Engineering

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 WITH FEATURES DATE: LIKE INSERTION/DELETION OF A CHARACTER, WORD AND SENTENCE

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

/* PROGRAM FOR TEXT EDITOR*/ #include<stdio.h> #include<conio.h> #include<string.h> void main() { FILE *fn,*fd; char int 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"); line[20][20],fname[20],str[30],op; i,j,k,len=0,ch=1,sn,n;

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

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<=i) { if(j==i) { len=strlen(line[j]); line[j][len-1]='\0'; } fputs(line[j],fn); j++; } fclose(fn); if((op == 'N')||(op =='n')) printf("The file not saved\n"); break;

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

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

System Software Laboratory

MENU 1. NEW 2. OPEN 3. SAVE 4. 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

MENU 1. NEW 2. OPEN 3. SAVE 4. DELETE 5. EXIT 5

System Software Laboratory

RESULT: Thus the above program for text editor was executed successfully and the output was verified

Department of Computer Science and Engineering

You might also like