4.34 If Directive
The MPASM IF
directive begins a conditional block of
assembly code.
Suggested Replacement
The PIC Assembler's IF
directive is a direct
replacement for this directive.
The operand must be an absolute expression and if non-zero, then the code following
the IF
up to the next matching ELSE
,
ELSIF
or ENDIF
will be assembled. If the
operand 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.
IF DEMO
call demo_mode
ELSE
call play_mode
ENDIF
Assembly code in both true and false cases is always scanned and
interpreted, but the machine code corresponding to the 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 so, should not be used inside an IF
-
ENDIF
construct.
Although the MPASM assembler allows you to use a #IF
form of this directive, note that it is still an assembler directive. The PIC
Assembler's #if
directive is a preprocessor directive, hence
will be looking at the result of a preprocessor expression (potentially
using preprocessor symbols), not an assembler expression (potentially using
assembler symbols). If you migrate your code to use the preprocessor directive,
ensure that you also examine the expressions involved, defining as required the
equivalent preprocessor macros using either the#define
directive or
-D
option.