7.4.2. MACRO and MEND

The MACRO directive marks the start of the definition of a macro. Macro expansion terminates at the MEND directive. See Using macros for further information.

Syntax

Two directives are used to define a macro. The syntax is:

          MACRO
{$label}  macroname {$parameter{,$parameter}...}
          ; code
          MEND

where:

$label

is a parameter that is substituted with a symbol given when the macro is invoked. The symbol is usually a label.

macroname

is the name of the macro. It must not begin with an instruction or directive name.

$parameter

is a parameter that is substituted when the macro is invoked. A default value for a parameter can be set using this format:


$parameter="default value"

Double quotes must be used if there are any spaces within, or at either end of, the default value.

Usage

If you start any WHILE...WEND loops or IF...ENDIF conditions within a macro, they must be closed before the MEND directive is reached. See MEXIT if you need to allow an early exit from a macro, for example from within a loop.

Within the macro body, parameters such as $label, $parameter can be used in the same way as other variables (see Assembly time substitution of variables). They are given new values each time the macro is invoked. Parameters must begin with $ to distinguish them from ordinary symbols. Any number of parameters can be used.

$label is optional. It is useful if the macro defines internal labels. It is treated as a parameter to the macro. It does not necessarily represent the first instruction in the macro expansion. The macro defines the locations of any labels.

Use | as the argument to use the default value of a parameter. An empty string is used if the argument is omitted.

In a macro that uses several internal labels, it is useful to define each internal label as the base label with a different suffix.

Use a dot between a parameter and following text, or a following parameter, if a space is not required in the expansion. Do not use a dot between preceding text and a parameter.

Macros define the scope of local variables (see LCLA, LCLL, and LCLS).

Macros can be nested (see Nesting directives).

Examples

 ; macro definition
                MACRO                 ; start macro definition
$label          xmac    $p1,$p2
                ; code
$label.loop1    ; code
                ; code
                BGE     $label.loop1
$label.loop2    ; code
                BL      $p1
                BGT     $label.loop2
                ; code
                ADR     $p2
                ; code
                MEND                  ; end macro definition
 ; macro invocation
abc             xmac    subr1,de      ; invoke macro
                ; code                ; this is what is
abcloop1        ; code                ; is produced when
                ; code                ; the xmac macro is
                BGE     abcloop1      ; expanded
abcloop2        ; code
                BL      subr1
                BGT     abcloop2
                ; code
                ADR     de
                ; code

Using a macro to produce assembly-time diagnostics:

        MACRO                        ; Macro definition
        diagnose  $param1="default"  ; This macro produces
        INFO      0,"$param1"        ; assembly-time diagnostics
        MEND                         ; (on second assembly pass)
 ; macro expansion
        diagnose            ; Prints blank line at assembly-time
        diagnose "hello"    ; Prints "hello" at assembly-time
        diagnose |          ; Prints "default" at assembly-time
Copyright © 2000, 2001 ARM Limited. All rights reserved.ARM DUI 0068B
Non-Confidential