Skip to main content

IAR Embedded Workbench for Arm 9.70.x

Conditional assembly directives

In this section:
Syntax

ELSE

ELSEIF condition

ENDIF

IF condition

Parameters

condition

One of these:

An absolute expression

The expression must not contain forward or external references, and any non-zero value is considered as true.

string1=string2

The condition is true if string1 and string2 have the same length and contents.

string1<>string2

The condition is true if string1 and string2 have different length or contents.

Description

Use the IF, ELSE, and ENDIF directives to control the assembly process at assembly time. If the condition following the IF directive is not true, the subsequent instructions do not generate any code (that is, it is not assembled or syntax checked) until an ELSE or ENDIF directive is found.

Use ELSEIF to introduce a new condition after an IF directive. Conditional assembly directives can be used anywhere in an assembly, but have their greatest use in conjunction with macro processing.

All assembler directives (except for END) as well as the inclusion of files can be disabled by the conditional directives. Each IF directive must be terminated by an ENDIF directive. The ELSE directive isand ENDIF directives are optional, and if used, must be inside an IF...ENDIF block. IF...ENDIF and IF...ELSE...ENDIF blocks can be nested to any level.

Example

This example uses a macro to add a constant to a register

?add        macro   a,b,c
            if      _args == 2
            adds    a,a,#b
            elseif  _args == 3
            adds    a,b,#c
            endif
            endm

            name    addWithMacro
            section MYCODE:CODE(2)
            arm

main        ?add    r1,0xFF         ; This,
            ?add    r1,r1,0xFF      ; and this,
            adds    r1,r1,#0xFF     ; are the same as this.

            end