macro processor -class
macro processor -class
1
Introduction
Concept
(module programming)
2
Introduction
» The MACRO statement identifies the beginning of a macro definition
» •The entries in the operand field identify the parameter of the macro instruction
» •The MEND assembler directive marks the end of the macro definition
» •A macro invocation statement gives the name of the macro instruction being
4
Basic macro processor
functions :Macro Definition &
Expansion
* Two new assembler directives are used in macro definition-
» MACRO:identify the beginning of a macro definition-MEND:identify the
end of a macro definition
» * Prototype for the macro
– Each parameter begins with ‘&’
Name MACRO Parameters
:
Body
:
MEND
– Body: the statements that will be generated as the
expansion of themacro.
5
Macro expansion
Each macro invocation statement will be expanded
into the statements that form the body of the macro.
Arguments from the macro invocation are substituted
for the parameters in the macro prototype (according
to their positions).
» In the definition of macro: parameter
6
Macro vs. Subroutine
Macro
» the statement of expansion are generated each time the
macro are invoked
Subroutine
» the statement in a subroutine appears only once
8
Macro Processor
Source
Macro Expanded Compiler or obj
Code
(with macro) Processor Code Assembler
9
Expanded program
14
15
Macro Definition
copy code
parameter substitution
conditional macro expansion
macro instruction defining macros
16
Copy code -- Example
{
STX DATA3 STA DATA1
MEND STB DATA2
. STX DATA3
STRG .
{
. STA DATA1
STRG STB DATA2
. STX DATA3
. .
17
Parameter Substitution --
Example
{
STX &a3 STA DATA1
MEND STB DATA2
. STX DATA3
STRG DATA1, DATA2, DATA3 .
{
. STA DATA4
STRG DATA4, DATA5, DATA6 STB DATA5
. STX DATA6
. .
18
Parameter Substitution
» Positional argument
STRG DATA1, DATA2, DATA3
GENER ,,DIRECT,,,,,,3
» Keyword argument
STRG &a3=DATA1, &a2=DATA2, &a1=DATA3
GENER TYPE=DIRECT, CHANNEL=3
19
Conditional macro expansion
20
21
22
23
Nested macro calls
24
Nested macro definition
25
One-Pass Macro Processor
Prerequisite
» every macro must be defined before it is called
Sub-procedures
» macro definition: DEFINE
» macro invocation: EXPAND
NAMTAB
PROCESSLINE
CALL
EXPAND ARGTAB
26
28
29
Data Structures -- Global
Variables
DEFTAB
NAMTAB
ARGTAB
EXPANDING
30