Macros and Macro Processors

 Macro is a unit of specification for program generation through expansion (like a function).

Macro consists of a name, a set of formal parameters and a body of code. When a macro is called the using the macro name with the set of actual parameters then the name with the parameters is replaced by the code generated from its body. This process is called macro expansion.


Two types of Macro Expansion


1. Lexical expansion.

2. Semantic expansion.


Lexical Expansion

It is the process of replacing one character string with another character string during program generation.( actual parameters in place of formal parameters).

Semantic Expansion

In simple words, semantic expansion implies generation of instructions tailored to the requirements of a specific usage.


Macro Definition and Call


A macro definition starts with a reserved keyword MACRO and ends with a keyword MEND. The statements enclosed in between these keywords include macro definition and its body.

note: If you have any prior experience in programming you can relate macros with functions.

eg:

MACRO
INCR                    &MEM_VAL,&INCR_VAL, &REG
MOVER               &REG, &MEM_VAL
ADD                     &REG, &INCR_VAL
MOVEM              &REG, &MEM_VAL
MEND

In the above program, you can see that the name of the macro is INCR and it has following parameters MEM_VAL, INCR_VAL, REG. The above program just does a swap of values between MEM_VAL and INCR_VAL.



Comments

Popular posts from this blog

Managing Output with Manipulators in C++

What is sniffing?

Creating a bootable USB.