User manual
ST assembler ST Assembler-Linker
32/89 Doc ID 11392 Rev 4
4.6 Conditional assembly #IF, #ELSE and #ENDIF directives
Conditional assembly is used to choose to ignore or select whole areas of assembler code.
This is useful for generating different versions of a program by setting a particular variable in
an INCLUDE file that forces the use of certain pieces of code instead of others.
There are three main directives used to perform conditional assembly, as shown in Table 13.
The condition given with the '#IF' may take the form of any numeric expression. The rule for
deciding whether it resolves to 'true' or 'false' is simple: if it has a zero value then it is false,
else it is true. These directives should NOT start at column 1 of the line, reserved for labels.
For example:
#IF {count eq 1}
%OUT 'true'
#ELSE
%OUT 'false'
#ENDIF
This sequence would print true if the label count did equal 1, and ‘false’ if it did not.
For example:
#IF {count gt 1}
%OUT count more than one
#IF {count gt 2}
%OUT ...and more of TWO !
#ELSE
%OUT ...but not more than two!
#ENDIF
#ELSE
%OUT count not more than one
#ENDIF
As you can see, conditionals may be nested, the #ELSE and #ENDIF directive are assumed
to apply to the most recent unterminated #IF.
Other special #IF directives are available as shown in Table 1 4.
.
Table 13. Summary of conditional assembly directives
Directive Usage
#IF
Marks the start of the conditional and decides whether the following zone will be
assembled or not.
#ELSE Optionally reserves the condition of the previous #IF for the following zone.
#ENDIF Marks the end of the previous #IF's.
Table 14. Other special #IF directives
Directive Usage
#IF1 and
#IF2
Requires no conditional argument. If the appropriate pass is. being assembled, the
condition is considered 'true'; for instance #IF1 will be considered true while the
assembler is in first pass, #IF2 while in the second pass.
#IFDEF Checks for label definition.