5.8.52. MACRO directive

The MACRO directive marks the start of the definition of a macro. Macro expansion terminates at the MEND directive. See Chapter 5 Basic Assembly Language Programming in the ARM Software Development Toolkit User Guide for further information.

Syntax

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

	MACROmacro_prototype	; code	MEND

The MACRO directive must be followed by a macro prototype statement on the next line. The syntax of the macro prototype statement is:

{$label} 	macroname {$parameter1{,$parameter2}...}

where:

$label

is a parameter that is substituted with a symbol given when the macro is invoked. The symbol is usually, but not necessarily, 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 may 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

There must be no unclosed WHILE...WEND loops or unclosed IF...ENDIF conditions when the MEND directive is reached. See MEXIT directive 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 directive, LCLL directive and LCLS directive.

Macros can be nested. See Nesting directives.

Example

				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
abc				xmac		subr1,de				; invoke macro
				; code						; this is what is
abcloop1				; code						; is produced when
				; code						; the macro is
				BGE		abcloop1				; expanded
abcloop2				; code
				BL		subr1
				BGT		abcloop2
				; code
				ADR		de
				; code	
Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0041C
Non-Confidential