4.40 Macro Directive
The MPASM MACRO
directive defines a macro.
Suggested Replacement
The PIC Assembler's MACRO
directive is direct
replacement.
Within a macro definition, the &
character can be
used to permit the concatenation of macro arguments with other text, but is removed
in the actual expansion. For example:
loadPort MACRO port, value
movlw value
movwf PORT&port
ENDM
will load PORTA
if port
is
A
when called, etc. The special meaning of the
&
token in macros implies that you must only use the
and
form of the bitwise AND operator.
A comment can be suppressed within the expansion of a macro by opening the comment
with two semicolons, ;;
.
When invoking a macro, the argument list must be comma-separated. If it is desired to
include a comma (or other delimiter such as a space) in an argument then angle
brackets <
and >
can be used to quote.
If an argument is preceded by a percent sign, %
, that argument will
be evaluated as an expression and passed as a decimal number, rather than as a
string. This is useful if evaluation of the argument inside the macro body would
yield a different result.
The nul
operator can be used within a macro to test a macro
argument, for example:
IF nul arg3 ;argument was not supplied.
...
ELSE ;argument was supplied
...
ENDIF