Skip to main content

IAR Embedded Workbench for RH850 3.20.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, ELSEIF, 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 ELSEIF condition is true or 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 and 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 direct page memory location:

addMem      macro   loc,val         ; loc is a direct page memory
                                    ; location, and val is an
                                    ; 8-bit value to add to that
                                    ; location.
            if      val = 0
                                    ; Do nothing.

            elseif  val < 16
            mov     loc,r6
            ld.w    0[r6],r7
            add     val,r7
            st.w    r7,0[r6]
            else
            mov     loc,r6
            ld.w    0[r6],r7
            addi    val,r7,r7
            st.w    r7,0[r6]
            endif
            endm
            module  addWithMacro
            section CODE:CODE
            code

addSome     addMem  0xa0,0          ; Add 0 to memory loc. 0xa0.
            addMem  0xa0,1          ; Add 1 to the same address.
            addMem  0xa0,2          ; Add 2 to the same address.
            addMem  0xa0,3          ; Add 3 to the same address.
            addMem  0xa0,47         ; Add 47 to the same address.
            jmp     [lp]
            end