Skip to main content

IAR Embedded Workbench for RL78 5.20

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:

; If the second argument to the addMem macro is 1, 2, or 3,
; it generates the equivalent number of INC instructions. For any
; other non-zero value of the second argument, it generates an
; LDA, an ADD, and an STA instruction.

addMem      macro   loc,val         ; loc is a direct page memory
                                    ; location, and val is a
                                    ; 32-bit value to add to that
                                    ; location.
            if      val = 0
                                    ; Do nothing.
            elseif  val = 1
            inc     loc
            elseif  val = 2
            inc     loc
            inc     loc
            elseif  val = 3
            inc     loc
            inc     loc
            inc     loc
            else
            movw    AX, loc
            addw    AX, #val
            movw    loc, AX
            endif
            endm

            module  addWithMacro
            section CODE:CODE
            code
addSome     addMem  0xa0,0          ; Add 0 to mem location 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
            ret
            end