0% found this document useful (1 vote)
2K views

IMPLEMENTATION OF MACRO PROCESSOR System Software Lab Program

The document describes the implementation of a macro processor. It defines a macro structure to store label, operation code, and operand for each macro definition. It reads in an input file containing macro definitions and code, identifies macros, and replaces macro names in the code with the defined macro body, writing the expanded output to a new file.

Uploaded by

Balaji Shanmugam
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
2K views

IMPLEMENTATION OF MACRO PROCESSOR System Software Lab Program

The document describes the implementation of a macro processor. It defines a macro structure to store label, operation code, and operand for each macro definition. It reads in an input file containing macro definitions and code, identifies macros, and replaces macro names in the code with the defined macro body, writing the expanded output to a new file.

Uploaded by

Balaji Shanmugam
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

IMPLEMENTATION OF MACRO PROCESSOR #include<stdio.h> #include<stdlib.h> #include<conio.

h> struct macro { char l[10]; char oc[10]; char op[10]; }m[20]; int size=0; void main() { FILE *fp,*fp1; int i; char label[10],opcode[10],operand[10],mname[10]; clrscr(); fp=fopen("macro.txt","r"); fp1=fopen("output.txt","w"); while(strcmp(opcode,"END")!=0) { fscanf(fp,"%s%s%s",&label,&opcode,&operand); if (strcmp(opcode,"MACRO")==0) { strcpy(mname,label); while(strcmp(opcode,"MEND")!=0) { strcpy(m[size].l,label); strcpy(m[size].oc,opcode); strcpy(m[size].op,operand); size++; fscanf(fp,"%s%s%s",&label,&opcode,&operand); } } else { if (strcmp(mname,opcode)==0) { fputc('.',fp1); fprintf(fp1,"%s\t%s\t%s\n",m[0].l,m[0].oc,m[0].op); for(i=1;i<size;i++) { fprintf(fp1,"%s\t%s\t%s\n",m[i].l,m[i].oc,m[i].op); } } else fprintf(fp1,"%s\t%s\t%s\n",&label,&opcode,&operand);

}//else }//while Getch(); } Output: i/p File: macro.txt COPY START A1 MACRO _ LDA _ ADD _ SUB _ STA _ MEND FIRST CLEAR _ A1 ALPHA RESW INCR RESW ONE WORD BETA RESW _ END o/p file: output.txt COPY START FIRST CLEAR .A1 MACRO _ LDA _ ADD _ SUB _ STA ALPHA RESW INCR RESW ONE WORD BETA RESW _ END 1000 A _ ALPHA INCR ONE BETA 1 1 1 1 1000 _ ALPHA INCR ONE BETA _ A _ 1 1 1 1 -

You might also like