Macro Processor
A Macro instruction is the notational convenience for the programmer. For every occurrence of macro the whole macro body or macro block of statements gets expanded in the main source code. Thus Macro instructions make writing code more convenient.
Salient features of Macro Processor:
- Macro represents a group of commonly used statements in the source programming language.
- Macro Processor replaces each macro instruction with the corresponding group of source language statements. This is known as the expansion of macros.
- Using Macro instructions programmer can leave the mechanical details to be handled by the macro processor.
- Macro Processor designs are not directly related to the computer architecture on which it runs.
- Macro Processor involves definition, invocation, and expansion.
Macro Definition and Expansion:
Line Label Opcode Operand 5 COPY START 0 10 RDBUFF MACRO &INDEV, &BUFADR 15 . . 90 95 MEND
- Line 10:
RDBUFF (Read Buffer) in the Label part is the name of the Macro or definition of the Macro. &INDEV and &BUFADR are the parameters present in the Operand part. Each parameter begins with the character &. - Line 15 – Line 90:
From Line 15 to Line 90 Macro Body is present. Macro directives are the statements that make up the body of the macro definition. - Line 95:
MEND is the assembler directive that means the end of the macro definition.
Macro Invocation:
Line Label Opcode Operand 180 FIRST STL RETADR 190 CLOOP RDBUFF F1, BUFFER 15 . . 255 END FIRST
Line 190:
RDBUFF is the Macro invocation or Macro Call that gives the name of the macro instruction being invoked and F1, BUFFER are the arguments to be used in expanding the macro. The statement that form the expansion of a macro are generated each time the macro is invoked.