2.8.1. Test-and-branch macro example

Before ARMv6T2, a test-and-branch operation required two ARM instructions to implement.

You can define a macro definition such as this:

$label  TestAndBranch  $dest, $reg, $cc

$label  CMP     $reg, #0
        B$cc    $dest

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). You must give values to the parameters when you invoke the macro. The assembler substitutes the values you give into the code.

This macro can be invoked as follows:

test    TestAndBranch    NonZero, r0, NE

After substitution this becomes:

test    CMP     r0, #0
        BNE     NonZero
Copyright © 2002-2005 ARM Limited. All rights reserved.ARM DUI 0204F