Machine Independent Macro Processor Features
Machine Independent Macro Processor Features
1
● 1. Concatenation of macro parameters
● 2. Generation of unique labels
● 3. Conditional macro expansion
● 4. Keyword macro parameters
2
1. Concatenation of Macro Parameters
● Pre-concatenation
» LDA X&ID1
● Post-concatenation
» LDA X&ID→1
● Example: Figure 4.6
3
2. Generation of Unique Labels
SUM MACRO &X,&Y
START
LDA &X LDA &P
LOOP COMP B LOOP COMP B
JLT LOOP JLT LOOP
….. …..
MEND
LDA &M
LOOP COMP B
START JLT LOOP
SUM P,Q …..
SUM M,N
DUPLICATION
END
OF LABELS!!!
4
SUM MACRO &X,&Y
START
LDA &X LDA &P
COMP B COMP B
JLT *-3 JLT *-3
….. …..
MEND
LDA &M
COMP B
START JLT *-3
SUM P,Q …..
SUM M,N
NOT SUITABLE
END
FOR LONG JUMPS
5
Unique Labels
SUM MACRO &X,&Y START
LDA &X LDA &P
$LP COMP B $AALP COMP B
JLT $AALP
JLT $LP
………
…..
MEND
LDA &M
START $ABLP COMP B
JLT $ABLP
SUM P,Q
……..
SUM M,N END
END
6
● Replace symbol $ with $AA, $AB, $AC…… for
each invocation .
● There is no chance of label duplication here.
7
3. Conditional Macro Expansion
● IF-ELSE-ENDIF
● WHILE-ENDW
● Macro-time variables
8
SUM MACRO &T,&X,&Y START
IF (&T EQ 1)
LDA &X LDA &P
ELSE
LDA &N
LDA &Y
ENDIF END
MEND
START
SUM 1,P,Q
SUM 0,M,N
END 9
● Macro-time variables
» any symbol that begins with the character &
and that is not a macro parameter
» macro-time variables are initialized to 0
» macro-time variables can be changed with their
values using SET
10
SUM MACRO &T,&X,&Y
IF (&T EQ 1)
&S SET 1
ENDIF START
IF (&S EQ 1)
LDA &X LDA &P
ELSE
LDA &N
LDA &Y
ENDIF END
MEND
START
SUM 1,P,Q
SUM 0,M,N
END
11
SUM MACRO &LIMIT,&X
&CTR SET 1
START END
SUM 2,P
SUM 1,M
END
12
4. Keyword Macro Parameters
13
SUM MACRO &A=1,&B=2,&C=3,&D=,&E=5,&F=,&G=7,&H=8
………
START
SUM 10,’ ‘,100,’ ‘,’ ‘, ’ ‘, ’ ‘ ,’ ‘
SUM ‘ ‘,20,10,’ ‘,’ ‘, ’ ‘, ’ ‘, 30
START
SUM A=10,C=100 KEYWORD MACRO
PARAMETERS
SUM C=10,H=30,B=20
14
● Each argument value is written with a keyword that
names the corresponding parameter.
● Arguments may appear in any order.
● Each keyword parameter is followed by an equal
sign. (giving default value is optional)
15