ARM Assembler Directives for Macro Definition

Macros are useful when you need a group of instructions or directives frequently. The ARM assembler will replace the macro name with its definition. Macros may contain calls to other macros, nested up to 255 levels.

Two directives define a macro, MACRO and MEND.

MACRO
{$label}    macroname {$parameter1}{,$parameter2}{,$parameter3}..
...code...
MEND

A macro prototype statement must appear on the first line following the MACRO directive. The prototype tells the assembler the name of the macro, macroname, and its parameters. A label is optional, but is useful if the macro defines internal labels. Any number of parameters can be used; each must begin with $ to distinguish it from ordinary program symbols.

Within the macro body, $label, $parameter, and so on, can be used in the same way as any other variables. The $label parameter is simply treated as another parameter to the macro. The macro itself describes which labels are defined where. The label does not represent the first instruction in the macro expansion. For example, it is useful in a macro that uses several internal labels, such as a loop, to define each internal label as the base label with a different suffix.

Sometimes, a value appends a macro parameter or label. Separate the appended value by a dot. After the assembler recognizes the end of the parameter and label, the assembler ignores the dot.

For example:

$label.1
$label.loop
$label.$count

Default values can be set for parameters by following them with an equals sign and the default value. If the default has a leading or trailing space, the whole value should appear in quotes, as shown in the following code example.

...{$parameter="default value"}

The MEND directive signifies the end of the macro definition. If the macro contains WHILE/WEND loops, or contains conditional assembly, the WHILE/WEND loop must close before execution reaches the MEND directive. You can also terminate macro expansion with the MEXIT directive, used in conjunction with WHILE/WEND or conditional assembly.

See Also

ARM Assembler Directives | ARM Assembler | ARM Assembler Macros | ARM Initialization and Layout Directives | ARM Linking Directives | ARM Diagnostic Directives | ARM Directives for Conditional Assembly | ARM Dynamic Listing Directive Options | ARM-Thumb Interworking Directives | ARM Constant and Variable Declarations | Miscellaneous ARM Directives

 Last updated on Thursday, April 08, 2004

© 1992-2003 Microsoft Corporation. All rights reserved.