• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Macroprocessor
 

Macroprocessor

on

  • 671 views

 

Statistics

Views

Total Views
671
Views on SlideShare
671
Embed Views
0

Actions

Likes
0
Downloads
15
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Macroprocessor Macroprocessor Document Transcript

    • Expno:…………. Date :…............. MACROPROCESSOR AIM: ALGORITHM:
    • 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) {
    • 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++;
    • 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(); }
    • 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
    • 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: