Page 64 - ARM 64 Bit Assembly Language
P. 64
48 Chapter 2
\@
This is a pseudo-variable used by the assembler to maintain a count of how many
macros it has executed. That number can be accessed with ‘\@’, but only within a macro
definition.
2.3.8.1 Macro example
The following definition specifies a macro SHIFT that will emit the instruction to shift a given
register left by a specified number of bits. If the number of bits specified is negative, then it
will emit the instruction to perform a right shift instead of a left shift.
1 .macro SHIFT a,b
2 .if \b < 0
3 asr \a, \a, #-\b
4 .else
5 lsl \a, \a, #\b
6 .endif
7 .endm
After that definition, the following code:
1 SHIFT x1, 3
2 SHIFT x4, -6
will generate these instructions:
1 lsl x1, x1, #3
2 asr x4, x4, #6
The meaning of these instructions will be covered in Chapter 3 and Chapter 4.
2.3.8.2 Recursive macro example
The following definition specifies a macro enum that puts a sequence of numbers into memory
by using a recursive macro call to itself:
1 .macro enum first=0, last=5
2 .long \first
3 .if \last-\first
4 enum "(\first+1)",\last
5 .endif
6 .endm