Using Macro Arguments

You can refer to the parameters directly by name. The following listing shows the setup macro, which moves an integer into a register and branches to the label _final_setup.

Listing: Setup Macro Definition
setup:      .macro name
             mov    name,d0

             jsr   _final_setup

            .endm

The following listing shows a way to invoke the setup macro.

Listing: Calling Setup Macro
           #define VECT=0
           setup   VECT

The following listing shows how the assembler expands the setup macro.

Listing: Expanding Setup Macro
           move    VECT, d0
           jsr    _final_setup

If you refer to the named macro parameters in the macro body, you can precede or follow the macro parameter with &&. This lets you embed the parameter in a string. For example, The following listing shows the smallnum macro, which creates a small float by appending the string E-20 to the macro argument.

Listing: Smallnum Macro Definition
smallnum:    .macro    mantissa
             .float    mantissa&&E-20

             .endm

The following listing shows a way to invoke the smallnum macro.

Listing: Invoking Smallnum Macro
smallnum  10

The following listing shows how the assembler expands the smallnum macro.

Listing: Expanding Smallnum Macro
.float     10E-20

Macro syntax includes positional parameter references (this feature can provide compatibility with other assemblers). For example, The following listing shows a macro with positional references \1 and \2.

Listing: Doit Macro Definition
doit:    .macro
         move     \1,d0

         jsr    \2

         .endm

The following listing shows an invocation of this macro, with parameter values 10 and print.

Listing: Invoking Doit Macro
doit    10,print

The following listing shows the macro expansion

Listing: Expanding Doit Macro
    move   10,d0
    jsr   print