Z80 Assembly 20: Writing a Simple Macro (Code Generation)
What is a Macro? A macro is a sequence of instructions or data definitions that you define once and can then reuse multiple times throughout your code by simply typing the macro’s name. When the assembler encounters the macro name, it substitutes the entire predefined block of code in its place. Macro vs. Subroutine: Subroutine (CALL): Saves memory by running one copy of the code, but is slower because it incurs the overhead of the CALL and RET instructions (17 cycles). Macro: Faster because the code is pasted directly (inline) every time it’s used, but increases the size of the assembled program. Defining a Simple Macro The syntax for defining a macro varies slightly between assemblers (e.g., TASM, Z80Asm, sjasmplus), but they typically use MACRO and ENDM or DEFM. ...