Page 63 - ARM 64 Bit Assembly Language
P. 63
GNU assembly syntax 47
2.3.8 Macros
The directives .macro and .endm allow the programmer to define macros that the assembler
expands to generate assembly code. The GNU assembler supports simple macros. Some other
assemblers have much more powerful macro capabilities.
.macro macname
.macro macname macargs ...
Begin the definition of a macro called macname. If the macro definition requires argu-
ments, their names are specified after the macro name, separated by commas or spaces.
The programmer can supply a default value for any macro argument by following the
name with ‘=deflt’.
The following begins the definition of a macro called reserve_str, with two arguments. The
first argument has a default value, but the second does not:
1 .macro reserve_str p1=0 p2
When a macro is called, the argument values can be specified either by position, or by key-
word. For example, reserve_str 9,17 is equivalent to reserve_str p2=17,p1=9.After
the definition is complete, the macro can be called either as
reserve_str x,y
(with \p1 evaluating to x and \p2 evaluating to y), or as
reserve_str ,y
(with \p1 evaluating as the default, in this case 0, and \p2 evaluating to y). Other examples of
valid .macro statements are:
1 // Begin the definition of a macro called comm,
2 // which takes no arguments:
3 .macro comm
1 // Begin the definition of a macro called plus1,
2 // which takes two arguments:
3 .macro plus1 p, p1
4 // Write \p or \p1 to use the arguments.
.endm
End the current macro definition.
.exitm
Exit early from the current macro definition. This is usually used only within a .if or
.ifdef directive.