Module 3
Module 3
MACRO
PROCESSORS
Macros
● Macro instructions or Macros are single line abbreviations for groups of instructions.
● For every occurrence of this one line macro instruction, the macro processing assembler will substitute the
entire block.
Macro Instructions
● Example:
Start of definition
Macro name
A 1,DATA MACRO
A 2,DATA INCR INCR
A 3,DATA A 1,DATA
Repeated Sequence to be
A 2,DATA
code A 3,DATA
abbreviated
A 1,DATA INCR
A 2,DATA MEND
A 3,DATA
End of definition
Macros in C
● Arguments that are not specified, are presumed blank by macro processor.
Macro Instruction Arguments
● AIF and AGO permit conditional reordering of the sequence of macro expansion.
● AIF
○ Conditional branch
● AGO
● Machine instructions that appear in the expansion of a macro call can be selected based on condition.
● A macro can call itself (using AIF or AGO) so long as it doesn’t go into an infinite loop.
● Inner macro definition is not defined until after the outer macro has been called.
● Group of macros can be defined for subroutine calls with some standardized calling sequence.
● Individual macros have names of the associated subroutines (as given by the argument &SUB).
Macro Instruction defining Macros
MACRO
DEFINE &SUB Macro name: DEFINE
MACRO
&SUB &Y Dummy macro name
Definition CNOP 0,4 Align boundary
of macro Definition
BAL 1,*+8 Set reg 1 to parameter list pointer
DEFINE of macro
DC A(&Y) Parameter list pointer
&SUB
L 15,=V(&SUB) Address of subroutine
BALR1 4,15 Transfer control to subroutine
MEND
MEND
DEFINE COS
COS AR
BAL 1,*+8
DC A(AR) Address of AR
L 15,=V(COS) V denotes Address of external symbol
BALR14,15
2 pass Macro Processor
● Assumptions
○ Macro Definition Table Counter (MDTC) (next available entry in the MDT)
○ Macro Name Table Counter (MNTC) (next available entry in the MNT)
○ Argument List Array (ALA) (to substitute index markers for dummy arguments before storing macro definition)
2 pass Macro Processor
○ MDT
○ ALA
○ Macro Definition Table Pointer (MDTP) (indicates the next line of text to be used during macro expansion)
2 pass Macro Processor
Index Card
15 &LAB INCR &ARG1, &ARG2, &ARG3
16 #0 A 1,#1
17 A 2,#2
18 A 3,#3
19 MEND
MDT
2 pass Macro Processor
○ Each entry consists of a character string (macro name) and pointer to entry in MDT
PASS 1
MDTC <― 1
MNTC <― 1
No
Yes
Read next END GO TO PASS 2
source card psedo-op?
PASS 2
Read next
source card
(from pass 1) No
END Yes Supply expanded
Search MNT
pseudo-op? source file to
for match
assembler processing
with opcode
MACRO
&LAB INCR &ARG1, &ARG2, &ARG3
&LAB A 1, &ARG1
A 2, &ARG2
A 3, &ARG3
MEND
.
.
LOOP1 INCR DATA1,DATA2,DATA3
.
.
LOOP2 INCR DATA1,DATA2,DATA3
.
.
Example Pass1
MNT ALA
Index Card MDT Index Index Argument
1 INCRbbbb 1 0 LOOP1bbb
1 DATA1bbb
2 DATA2bbb
MDT 3 DATA3bbb
Index Card
1 &LAB INCR&ARG1,&ARG2,&ARG3
2 #0 A 1,#1 MDTC 6
4
5
2
3
1
3 A 2,#2 MNTC 1
2
4 A 3,#3
5 MEND
Example Pass 2
MNT ALA
Index Card MDT Index Index Argument
1 INCRbbbb 1 0 LOOP1bbb
1 DATA1bbb
2 DATA2bbb
MDT 3 DATA3bbb
Index Card
2 #0 A
LOOP1 1,#11,DATA1
A
3 A 2,#2
2,DATA2 MDTP 5
4
2
1
3
4 A 3,#3
3,DATA3
5 MEND
THE END!