4. GNU-Syntax Arm Assembly Macros¶
4.1. Macro Directive and Macro Definitions¶
The GNU-syntax form of a .macro directive and macro definition looks like this:
.macro <macro name>[, <parameter1>[, ..., <parameterN>]]
<model assembly statements>
.endm
where:
.macro - is the assembly directive that identifies the assembly source statement as the first line of a macro definition. For the GNU-syntax form, it must appear in the mnemonic field before the macro name.
<macro name> - is the name of the macro. After a macro has been defined, its name can then be used in the mnemonic field of an assembly statement to effect an invocation of the macro. For the GNU-syntax form, the macro name must be specified as the first operand of the .macro directive.
<parameter(s)> - are optional identifiers that serve as vehicles for operand arguments that are passed into a macro when a macro is invoked. Each parameter takes on the value of the argument that is specified in the macro invocation at the corresponding operand position. For the GNU-syntax form, the use of commas to separate operands of the .macro directive are optional as long as there is at least one blank space between each operand and the next.
<model assembly statements> - are instructions or directives that are executed each time the macro is invoked.
.endm - is an assembler directive that delimits the end of the current macro definition.
4.2. Referencing Macro Parameters and Local Labels¶
Consider the definition of an assembly macro named COMPARE64 specified in GNU-syntax form:
/* COMPARE64 macro definition - GNU-syntax
.macro COMPARE64, x_hi, x_lo, y_hi, y_lo
CMP \x_hi, \y_hi
BNE .L_\@
CMP \x_lo, \y_lo
.L_\@:
.endm
you’ll notice that parameter references must be delimited with a leading backslash (’') character in the context of the macro definition. Similarly, the local label is indicated with “.L_@” in the macro definition where the “@” part of the label name instructs the assembler to generate a unique ID in place of the “@” when it is used in a label definition.
Here is an example of an invocation of the COMPARE64 macro:
; COMPARE64 macro invocation
COMPARE64 r3, r2, r1, r0
The GNU-syntax form of the macro expands into the following sequence of assembly source:
; COMPARE64 macro invocation
CMP r3, r1
BNE .L_0
CMP r2, r0
.L_0: