![]() |
III.11.2 Macro Parameters Callable macros may have parameters, to allow more flexible use. The names of the formal parameters are specified in the macro definition behind the keyword MACRO, separated by commas. All parameter names of a macro must be different, valid symbols. Keywords cannot be used as parameter names. Macros may have any number of parameters, as long as they fit on one line. Parameter names are local symbols, which are known within the macro only. Outside the macro they have no meaning!
When called, actual arguments can be passed to the macro. The arguments must be separated by commas. Valid macro arguments are
Note: The keywords MACRO, EQU, SET, CODE, DATA, IDATA, XDATA, BIT,
and the ':' character cannot be passed as the first macro argument,
because they always start a symbol definition!
During macro expansion, these actual arguments replace the symbols of the
corresponding formal parameters, wherever they are recognized in the macro
body. The first argument replaces the symbol of the first parameter, the
second argument replaces the symbol of the second parameter, and so forth.
This is called substitution.
MY_SECOND MACRO CONSTANT, REGISTER MOV A,#CONSTANT ADD A,REGISTER ENDM MY_SECOND 42, R5 After calling the macro MY_SECOND, the body lines MOV A,#42 ADD A,R5 are inserted into the program, and assembled. The parameter names CONSTANT and REGISTER have been replaced by the macro arguments "42" and "R5".
The number of arguments, passed to a macro, can be less (but not greater)
than the number of its formal parameters. If an argument is omitted, the
corresponding formal parameter is replaced by an empty string.
The macro OPTIONAL has eight formal parameters: OPTIONAL MACRO P1,P2,P3,P4,P5,P6,P7,P8 . . <macro body> . . ENDM If it is called as follows, OPTIONAL 1,2,,,5,6 the formal parameters P1, P2, P5 and P6 are replaced by the arguments 1, 2, 5 and 6 during substitution. The parameters P3, P4, P7 and P8 are replaced by a zero length string.
For more flexible macro design, there must be a possibility to recognize
empty macro arguments, and to branch the macro expansion accordingly.
This can be performed with conditional assembly, using the IFB and IFNB
meta instructions.
|