6.1.9.22 If, Elsif, Else And Endif Directives
These directives implement conditional assembly.
The argument to IF
and ELSIF
must be a
constant expression. If this argument is non-zero, then the code following it up to the
next matching ELSE
, ELSIF
or ENDIF
will
be assembled. If the argument is zero, then the code up to the next matching
ELSE
or ENDIF
will not be output. At an
ELSE
, the sense of the conditional compilation will be inverted, while
an ENDIF
will terminate the conditional assembly block. Conditional
assembly blocks can be nested.
These directives do not implement a runtime conditional statement in the
same way that the C statement if
does; they are only evaluated when the
code is built. In addition, assembly code in both true and false cases is always scanned
and interpreted, but the machine code corresponding to instructions is output only if the
condition matches. This implies that assembler directives (e.g., EQU
) will
be processed regardless of the state of the condition expression and should not be used
inside an IF
construct.
For example:
IF ABC
goto aardvark
ELSIF DEF
goto denver
ELSE
goto grapes
ENDIF
ENDIF
In this example, if ABC
is non-zero, the first
goto
instruction will be assembled but not the second or third. If
ABC
is zero and DEF
is non-zero, the second
goto
instruction will be assembled but the first and third will not. If
both ABC
and DEF
are zero, the third
goto
instruction will be assembled.