| |||
| Home > Writing ARM Assembly Language > Using macros > Test-and-branch macro example | |||
In ARM code, and Thumb on a pre-Thumb-2 processor, a test-and-branch operation requires two ARM instructions to implement.
You can define a macro definition such as this:
MACRO
$label TestAndBranch $dest, $reg, $cc
$label CMP $reg, #0
B$cc $dest
MEND
The line after the MACRO directive is the macro
prototype statement. This defines the name (TestAndBranch)
you use to invoke the macro. It also defines parameters ($label, $dest, $reg,
and $cc). Unspecified parameters are substituted
with an empty string. For this macro you must give values for $dest, $reg and $cc to
avoid syntax errors. The assembler substitutes the values you give
into the code.
This macro can be invoked as follows:
test TestAndBranch NonZero, r0, NE
...
...
NonZero
After substitution this becomes:
test CMP r0, #0
BNE NonZero
...
...
NonZero