7.4.4. IF, ELSE, and ENDIF

The IF directive introduces a condition that is used to decide whether to assemble a sequence of instructions and/or directives. [ is a synonym for IF.

The ELSE directive marks the beginning of a sequence of instructions and/or directives that you want to be assembled if the preceding condition fails. | is a synonym for ELSE.

The ENDIF directive marks the end of a sequence of instructions and/or directives that you want to be conditionally assembled. ] is a synonym for ENDIF.

Syntax

    IF logical-expression     ...    {ELSE      ...}     ENDIF

where:

logical-expression

is an expression that evaluates to either {TRUE} or {FALSE}.

See Relational operators.

Usage

Use IF with ENDIF, and optionally with ELSE, for sequences of instructions and/or directives that are only to be assembled or acted on under a specified condition.

IF...ENDIF conditions can be nested (see Nesting directives).

Examples

Example 7.3 assembles the first set of instructions if NEWVERSION is defined, or the alternative set otherwise.

Example 7.3. Assembly conditional on a variable being defined

        IF :DEF:NEWVERSION
            ; first set of instructions/directives
        ELSE
            ; alternative set of instructions/directives
        ENDIF

Invoking armasm as follows defines NEWVERSION, so the first set of instructions and directives are assembled:

armasm -PD "NEWVERSION SETL {TRUE}" test.s

Invoking armasm as follows leaves NEWVERSION undefined, so the second set of instructions and directives are assembled:

armasm test.s

Example 7.4 assembles the first set of instructions if NEWVERSION has the value {TRUE}, or the alternative set otherwise.

Example 7.4. Assembly conditional on a variable being defined

        IF NEWVERSION = {TRUE}
            ; first set of instructions/directives
        ELSE
            ; alternative set of instructions/directives
        ENDIF

Invoking armasm as follows causes the first set of instructions and directives to be assembled:

armasm -PD "NEWVERSION SETL {TRUE}" test.s

Invoking armasm as follows causes the second set of instructions and directives to be assembled:

armasm -PD "NEWVERSION SETL {FALSE}" test.s
Copyright © 2000, 2001 ARM Limited. All rights reserved.ARM DUI 0068B
Non-Confidential