Professional Documents
Culture Documents
Basic Macro Processor Functions
Basic Macro Processor Functions
Introduction
A macro instruction (abbr. macro) is a notational convenience for the programmer. A macro represents a commonly used group of statements in the source programming language. The macro processor replaces each macro instruction with the corresponding group of source language statements.
Introduction (contd)
The mostly common use of macro processors is in assembler language programming. The design of a macro processor is not directly related to the architecture of the computer on which it is to run.
Macro definition
Two new assembler directives are used in macro definition.
macro_name MACRO ¶1, ¶2 ...... MEND
The macro name and parameters define a pattern or prototype for the macro instructions used by the programmer. Following the MACRO directive are the statements that make up the body of the macro definition.
Macro invocation
A macro invocation statement gives the name of the macro instruction being invoked and the arguments to be used in expanding the macro. The process of macro invocation and subroutine call are quite different.
The statements that form the expansion of a macro are generated (and assembled) each time the macro in invoked. Statements in a subroutine appear only once, regardless of how many times the subroutine is called.
A macro definition
Use of Macro
Macro invocation
Macro expansion
The macro instruction definitions are deleted since they are no longer needed after the macros are expanded. Each macro invocation statement is expanded into the statements that form the body of the macro, with the arguments from the macro invocation substituted for the parameters in the macro prototype.
Source program
10
If MACROX is invoked, the macros RDBUFF and WRBUFF for SIC version are expanded.
11
Requirement: The definition of a macro must appear in the source program before any statements that invoke that macro.
12
13
The parameter &DEV The parameter &DEV has been converted to ?1, has been converted to ?1, &BUFADR has been &BUFADR has been converted to ?2, and converted to ?2, and &RECLTH has been &RECLTH has been converted to ?3. converted to ?3.
Algorithms
15
Algorithms (contd)
16
Algorithms (contd)
GETLINE reads aaline either from input file or GETLINE reads line either from input file or from DEFTAB. from DEFTAB.
17
A macro definition
MACRO-MEND pair
Macro invocation
10