Using Macro Arguments

You can refer to parameters directly by name. Setup Macro Definition shows the setup macro, which moves an integer into a register and branches to the label _final_setup. Calling Setup Macro shows a way to invoke the setup macro., and Expanding Setup Macro shows how the assembler expands the setup macro.

Listing 1. Setup Macro Definition
setup:  .macro name
         li r3,name

         bl _final_setup

         .endm
Listing 2. Calling Setup Macro
VECT:  .equ 0
       setup      VECT
Listing 3. Expanding Setup Macro
           li   r3,VECT
           bl   _final_setup

If you refer to 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, Smallnum Macro Definition shows the smallnum macro, which creates a small float by appending the string E-20 to the macro argument. Invoking Smallnum Macro shows a way to invoke the smallnum macro, and Expanding Smallnum Macro shows how the assembler expands the smallnum macro.

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

              endm
Listing 5. Invoking Smallnum Macro
smallnum  10


Listing 6. Expanding Smallnum Macro
.float     10E-20