III.11.8 Nested Macro Definitions
A macro body may also contain further macro definitions. However, these nested macro definitions aren't valid until the enclosing macro has been expanded! That means, the enclosing macro must have been called, before the nested macros can be called.
A macro, which can be used to define macros with arbitrary names, may look as follows:DEFINE MACRO MACNAME MACNAME MACRO DB 'I am the macro &MACNAME.' ENDM ENDMIn order not to overload the example with "knowhow", the nested macro only introduces itself kindly with a suitable character string in ROM. The callDEFINE Obiwanwould define the macroObiwan MACRO DB 'I am the macro Obiwan.' ENDMand the callDEFINE Skywalkerwould define the following macro:Skywalker MACRO DB 'I am the macro Skywalker.' ENDM
A macro is to insert a variable number of NOPs into the program. For this, a macro with a nested REPT block seems to be best-suited:REPEAT MACRO NOPS REPT NOPS NOP ENDM ENDMThe macro callREPEAT 4results in something like that:Line I Addr Code Source 9+ 1 N 0004 REPT 4 10+ 1 NOP 11+ 1 ENDM 12+ 2 0000 00 NOP 13+ 2 0001 00 NOP 14+ 2 0002 00 NOP 15+ 2 0003 00 NOP