Define macro with .macro and .endm. You can use a parametric macros - any parameter is addressable by %%1, %%2, %%3, ... For example, such code:

   .macro decadd
      adi %%1
   ; Use this macro
    decadd $22

will generate this:

   0000 ; Use this macro
   0000 87 22 ADI $22
   0001 27    DAA

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:

.macro xyz
loop%%M: inc a
   dec b
   jr nz,loop%%M

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.

results matching ""

    No results matching ""