You are on page 1of 3

ASSIGNMENT NO.

: 2
NAME OF THE STUDENT: Isha Bhausaheb Awhale
CLASS: TY CSE -2 - CORE
BATCH: C
ROLL NO.: 2203532
TITLE: Macro expansion

ASSIGNMENT NO: 2

TITLE: Macro expansion

PROBLEM STATEMENT: Design suitable data structures and implement macro


definition and macro expansion processing for a sample macro with positional
and keyword parameters.
THEORY:

Macro definition and Expansion

Definition : macro
• A macro name is an abbreviation, which stands for some related
lines of code. Macros are useful for the following purposes:
• · To simplify and reduce the amount of repetitive coding
• · To reduce errors caused by repetitive coding
• · To make an assembly program more readable.
• A macro consists of name, set of formal parameters and body of
code. The use of macro name with set of actual parameters is
replaced by some code generated by its body. This is called macro
expansion.
• Macros allow a programmer to define pseudo operations, typically
operations that are generally desirable, are not implemented as part
of the processor instruction, and can be implemented as a
sequence of instructions. Each use of a macro generates new
program instructions, the macro has the effect of automating writing
of the program.

Macro Expansion.

• A macro call leads to macro expansion. During macro expansion,


the macro statement is replaced by sequence of assembly
statements.
• In the above program a macro call is shown in the middle of the
figure. i.e. INITZ. Which is called during program execution? Every
macro begins with MACRO keyword at the beginning and ends with
the ENDM (end macro).whenever a macro is called the entire is
code is substituted in the program where it is called. So the
resultant of the macro code is shown on the right most side of the
figure. Macro calling in high level programming languages

PROGRAM:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

char line[80],t1[10],t2[20],t3[10],FPN[20],APN[20],mname[10];
int count , v1,v2,v3,v4;
FILE *ifp;

int main()
{
int t21,t31,index=1;
ifp= fopen("int.txt","r");
while(!feof(ifp))
{
fgets(line,179,ifp);
count = sscanf(line,"%s%s%s",t1,t2,t3);
if(strcmp("MACRO",t1)==0)
{
strcpy(mname,t2);
printf("\n macro name table");
printf("\n \n");
}
if(strcmp(mname,t2)==0)
{
strcpy(FPN,t3);
printf("\n\n\n**FORMAL PARAMETER NAME TABLE**");
printf("\n :\n");
printf("\nINDEX\t\t:MACRO NAME");
printf("\n%d\t:%s",index,FPN);
}
if(strcmp(mname,t1)==0)
{
strcpy(APN,t2);
printf("\n\n\n**ACTUAL PARAMETER NAME TABLE**");
printf("\n :\n");
printf("\nINDEX\t\t:MACRO NAME");
printf("\n%d\t:%s",index,APN);
}
}
}

Int.txt:
MACRO ADDS X
ADD AREG BREG MEND
START 100
MOVER AREG CREG
ADDS X1
SUB AREG CREG
END
OUTPUT:

macro definition and macro


CONCLUSION: We successfully implemented
expansion processing for a sample macro with positional and keyword
parameters.

You might also like