Macroprocessor

995 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
995
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
25
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Macroprocessor

  1. 1. Expno:…………. Date :…............. MACROPROCESSOR AIM: ALGORITHM:
  2. 2. Expno:…………. Date :…............. CODING: #include<stdio.h> #include<conio.h> #include<string.h> void expandmacro(); char a,p1[10],p2[10],p3[10], p[10],para[10][10]; int n,i=0,j=1,y=0,x=0; void main() { FILE *fmac,*fnam,*fdef; char a,label[10],opcode[10],operand[50],p1[10],p2[10],p3[10], p[10],para[10][10]; int n,i=0,j=1,y=0,x=0; fmac=fopen("macro.txt","r"); fnam=fopen("namtab.txt","w"); fdef=fopen("deftab.txt","w"); do { fscanf(fmac,"%s%s%s",label,opcode,operand); if(strcmp(opcode,"MACRO")==0) { fprintf(fnam,"%sn",label); fprintf(fdef,"%st%sn",label,operand); n=strlen(operand); for(i=0;i<=n;i++) { a=operand[i]; if(a!=',') { para[j][y++]=a; } if(a==',') { para[j][y]='0'; y=0; j++; } } do { fscanf(fmac,"%s%s%s",label,opcode,operand); for(i=1;i<=j;i++) { if(strcmp(para[i],operand)==0) {
  3. 3. Expno:…………. Date :…............. fprintf(fdef,"%st?%dn",opcode,i); } } if(operand[0]!='&') fprintf(fdef,"%st%sn",opcode,operand); }while(strcmp(opcode,"MEND")!=0); } } while(!feof(fmac)); fcloseall(); expandmacro(); } void expandmacro() { FILE *finp,*fnam,*fdef,*farg; int flag=0; char mname[10],label[10],opcode[10],operand[50]; finp=fopen("input.txt","r"); fnam=fopen("namtab.txt","r"); fdef=fopen("deftab.txt","r"); farg=fopen("argtab.txt","w"); fscanf(fnam,"%s",mname); do { fscanf(finp,"%s%s%s",label,opcode,operand); if(strcmp(mname,opcode)==0) { flag=1; if(flag==1) { printf("%st%st%sn",label,opcode,operand); n=strlen(operand); for(i=0;i<=n;i++) { a=operand[i]; if(a!=',') { para[j][y++]=a; } if(a==',') { para[j][y]='0'; y=0; j++;
  4. 4. Expno:…………. Date :…............. } } for(i=1;i<=j;i++) fprintf(farg,"%sn",para[i]); fclose(farg); flag=0; } fscanf(fdef,"%s%s",opcode,operand); farg=fopen("argtab.txt","r"); if(strcmp(opcode,mname)==0) { do { fscanf(fdef,"%s%s",opcode,operand); if(strcmp(operand,"?1")==0) { fscanf(farg,"%s",p); strcpy(operand,p); rewind(farg); } if(strcmp(operand,"?2")==0) { fscanf(farg,"%s%s",p,p1); strcpy(operand,p1); rewind(farg); } if(strcmp(operand,"?3")==0) { fscanf(farg,"%s%s%s",p,p1,p2); strcpy(operand,p2); rewind(farg); } printf("_t%st%sn",opcode,operand); } while(strcmp(opcode,"MEND")!=0); } } else printf("%st%st%sn",label,opcode,operand); }while(!feof(finp)); fcloseall(); }
  5. 5. Expno:…………. Date :…............. INPUT FILES: MACRO: COPY START 0 RDBUFF MACRO &INDEV,&BUFADR,&RECLTH - CLEAR X - CLEAR A - CLEAR S - LDT 4096 - TD &INDEV - JEQ *-3 - RD &INDEV - COMPR A,S - JEQ *+11 - STCH &BUFADR - TIXR T - JLT *-19 - STX &RECLTH - MEND- INPUT PROGRAM: FIRST STL RETADR CLOOP RDBUFF F1,BUFFER,LENGTH - LDA LENGTH - COMP #0 - JEQ ENDFIL ENDFIL J @RETADR RETADR RESW 1 LENGTH RESW 1 BUFFER RESB 4096 - END FIRST
  6. 6. Expno:…………. Date :…............. OUTPUT: FIRST STL RETADR CLOOP RDBUFF F1,BUFFER,LENGTH - CLEAR X - CLEAR A - CLEAR S - LDT 4096 - TD F1 - JEQ *-3 - RD F1 - COMPR A,S - JEQ *+11 - STCH BUFFER - TIXR T - JLT *-19 - STX LENGTH - MEND - ENDFIL J @RETADR RETADR RESW 1 LENGTH RESW 1 BUFFER RESB 4096 - END FIRST RESULT:

×