SPRU513Y August 2001 – June 2022 SM320F28335-EP
Assemble Conditional Blocks
.ifcondition
[.elseifcondition]
[.else]
.endif
The .if directive marks the beginning of a conditional block. The condition is required.
The .elseif directive identifies a block of code to be assembled when the .if expression is false (0) and the .elseif expression is true (nonzero). When the .elseif expression is false, the assembler continues to the next .elseif (if present), .else (if present), or .endif (if no .elseif or .else is present). The .elseif is optional in a conditional block, and more than one .elseif can be used. If an expression is false and there is no .elseif, the assembler continues with the code that follows a .else (if present) or a .endif.
The .else directive identifies code the assembler assembles when the .if expression and all .elseif expressions are false (0). The .else directive is optional; if an expression is false and there is no .else statement, the assembler continues with the code that follows the .endif. The .elseif and .else directives can be used in the same conditional block.
The .endif directive terminates a conditional block.
See Section 5.10.2 for information about relational operators.
This example shows conditional assembly:
1 0001 SYM1 .set 1
2 0002 SYM2 .set 2
3 0003 SYM3 .set 3
4 0004 SYM4 .set 4
5
6 If_4: .if SYM4 = SYM2 * SYM2
7 000000 0004 .byte SYM4 ; Equal values
8 .else
9 .byte SYM2 * SYM2 ; Unequal values
10 .endif
11
12 If_5: .if SYM1 <= 10
13 000001 000A .byte 10 ; Less than / equal
14 .else
15 .byte SYM1 ; Greater than
16 .endif
17
18 If_6: .if SYM3 * SYM2 != SYM4 + SYM2
19 .byte SYM3 * SYM2 ; Unequal value
20 .else
21 000002 0008 .byte SYM4 + SYM4 ; Equal values
22 .endif
23
24 If_7: .if SYM1 = 2
25 .byte SYM1
26 .elseif SYM2 + SYM3 = 5
27 000003 0005 .byte SYM2 + SYM3
28 .endif