//CREATION OF SINGLE PASS ASSEMBLER// #include #include #include struct a { char b[10][10]; }source[10]; struct a symtab[10]; struct a reg[10]; struct a opcode[10]; FILE *f1,*f2,*f3,*f4; int prolines,reglines,oplines,symlines,loc; void main () { int i,h,k=0,x,y,j,w; char ch; f1=fopen("source1.txt","r"); f2=fopen("register.txt","r"); f3=fopen("opcodes.txt","r"); f4=fopen("symbol.txt","w"); clrscr(); printf("\n the source program \n"); while(!feof(f1)) { for(i=0;i<4;i++) { fscanf(f1,"%s",&source[k].b[i]); printf("%s",source[k].b[i]); printf("\t"); } printf("\n"); k++; } getch(); clrscr(); prolines=k; k=0; printf("\n register table\n"); while(!feof(f2)) { for(i=0;i<2;i++) { fscanf(f2,"%s",®[k].b[i]); printf("%s",reg[k].b[i]); printf("\t"); } printf("\n"); k++; } getch(); clrscr(); reglines=k; k=0; printf("\n opcode table\n"); while(!feof(f3)) { for(i=0;i<2;i++) { fscanf(f3,"%s",&opcode[k].b[i]); printf("%s",opcode[k].b[i]); printf("\t"); } printf("\n"); k++; } getch(); clrscr(); oplines=k; loc=atoi(source[0].b[3]); printf("\nsymbol table\n"); for(i=0;i<10;i++) { if(strcmp(source[i].b[0],"*")!=0) { fprintf(f4,"%s\t%d\n",source[i].b[0],(loc+i)-1); printf("%s\t%d\n",source[i].b[0],(loc+i)-1); } printf("\n"); fprintf(f4,"\n"); } getch(); clrscr(); fclose(f1); fclose(f2); fclose(f3); fclose(f4); f4=fopen("symbol.txt","r"); k=0; while(!feof(f4)) //creation of symbol table struct { for(i=0;i<2;i++) { fscanf(f4,"%s",&symtab[k].b[i]); } k++; } symlines=k; printf("the assembeled code is \n"); prolines=prolines-2;//except start and end ch=source[7].b[2][0]; for(i=1;i{ w=x=y=h=0; printf("%d\t+\t",(loc+i)-1); //printing 1st col for(j=0;j{ if(strcmp(opcode[j].b[0],source[i].b[1])==0) { printf("%d\t",atoi(opcode[j].b[1])); //printing opcode h=1; } } if(h!=1) printf("0\t"); if(source[i].b[2][0]==ch) { w=1; printf("0\t%c",source[i].b[2][1]); } for(j=0;j{ if(strcmp(reg[j].b[0],source[i].b[2])==0) { //printing reg number printf("%d\t",atoi(reg[j].b[1])); x=1; } } if(x!=1 && w!=1) printf("0\t"); for(j=0;j{ if(strcmp(symtab[j].b[0],source[i].b[3])==0) { printf("%d",atoi(symtab[j].b[1])); y=1; } } if(y!=1&&w!=1) printf("000"); printf("\n"); } fclose(f4); getch(); }
|
No feedbacks found. Be the first to respond and make money from revenue sharing program.
|