Keil Logo

Test-and-branch macro example

4.22 Test-and-branch macro example

You can use a macro to perform a test-and-branch operation.

In ARM code in any processor and in Thumb code in processors before ARMv6T2, a test-and-branch operation requires two instructions to implement.
You can define a macro 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
Non-ConfidentialPDF file icon PDF versionARM DUI0379H
Copyright © 2007, 2008, 2011, 2012, 2014-2016 ARM. All rights reserved. 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.