Macros
Define macro with .macro and .endm. You can use a parametric macros - any parameter is addressable by %%1, %%2, %%3, ... For example, such code:
will generate this:
Local labels
Macros has no local label mechanism. So if you define a label in a macro, it unrolls to the same label, ending with a "redefine label" error message.
There is a workaround to define unique label for each macro unrolling:
Now it is safe to use this macro repeatedly, because special placeholder "%%M" is replaced by string "M_"+line number. It provides a good enough workaround for local labels.
Compound parameters
Let's imagine a macro:
If you use this macro in such form, everything is OK:
Two parameters is OK. But what if you need the first DB is something like db $de,$ad,$be,$ef
? You can use the compound parameter:
Rich syntax (v2.5.2+)
A macro can be defined by standard syntax as .macro name
, or more consistent way as name: .macro
or name .macro
.
Formal parameters (v2.5.2+)
Now you can name formal parameters too. For example - assume a macro cpymem for copy memory content. Such macro has three arguments - source, destination and length. The old form of macro has mute parameters, just referenced by its number:
New formal parameters, introduced in revision 2.5.2, allows to write this:
Preprocessor also check if the number of given parameters is sufficient for the macro, i.e. you cannot specify less parameters than formal, like cpymem 100, 200
.
All those named parameters are strictly local (in fact, they are replaced with its values before assembly phase).
Last updated