9.8 Conditional assembly directives

These directives allow you to conditionally assemble sequences of instructions and directives.

Syntax

.if[modifier] expression
    // ...
  [.elseif expression
    // ...]
  [.else
    // ...]
.endif

Operation

There are a number of different forms of the .if directive which check different conditions. Each .if directive must have a matching .endif directive. A .if directive can optionally have one associated .else directive, and can optionally have any number of .elseif directives.

You can nest these directives, with the maximum nesting depth limited only by the amount of memory in your computer.

The following forms if the .if directive are available, which check different conditions:

Table 9-17 .if condition modifiers

.if condition modifier Meaning
.if expr Assembles the following code if expr evaluates to non zero.
.ifne expr Assembles the following code if expr evaluates to non zero.
.ifeq expr Assembles the following code if expr evaluates to zero.
.ifge expr Assembles the following code if expr evaluates to a value greater than or equal to zero.
.ifle expr Assembles the following code if expr evaluates to a value less than or equal to zero.
.ifgt expr Assembles the following code if expr evaluates to a value greater than zero.
.iflt expr Assembles the following code if expr evaluates to a value less than zero.
.ifb text Assembles the following code if the argument is blank.
.ifnb text Assembles the following code if the argument is not blank.
.ifc string1 string2 Assembles the following code if the two strings are the same. The strings may be optionally surrounded by double quote characters ("). If the strings are not quoted, the first string ends at the first comma character, and the second string ends at the end of the statement (newline or semicolon).
.ifnc string1 string2 Assembles the following code if the two strings are not the same. The strings may be optionally surrounded by double quote characters ("). If the strings are not quoted, the first string ends at the first comma character, and the second string ends at the end of the statement (newline or semicolon).
.ifeqs string1 string2 Assembles the following code if the two strings are the same. Both strings must be quoted.
.ifnes string1 string2 Assembles the following code if the two strings are not the same. Both strings must be quoted.
.ifdef expr Assembles the following code if symbol was defined earlier in this file.
.ifndef expr Assembles the following code if symbol was not defined earlier in this file.

The .elseif directive takes an expression argument but does not take a condition modifier, and therefore always behaves the same way as .if, assembling the subsequent code if the expression is not zero, and if no previous conditions in the same .if .elseif chain were true.

The .else directive takes no argument, and the subsequent block of code is assembled if none of the conditions in the same .if .elseif chain were true.

Examples

    // A macro to load an immediate value into a register. This expands to one or
    // two instructions, depending on the value of the immediate operand.
    .macro get_imm, reg, imm
      .if \imm >= 0x10000
        movw \reg, #\imm & 0xffff
        movt \reg, #\imm >> 16
      .else
        movw \reg, #\imm
      .endif
    .endm

    // The first of these macro invocations expands to one movw instruction,
    // the second expands to a movw and a movt instruction.
  get_constants:
    get_imm r0, 42
    get_imm r1, 0x12345678
    bx lr
Non-ConfidentialPDF file icon PDF versionDUI0774J
Copyright © 2014–2017, 2019 Arm Limited or its affiliates. All rights reserved.