Slide 12.3: Conditional structures
Slide 12.5: Decision directives (cont.)
Home

Decision Directives


The Microsoft assembler provides decision directives (.IF, .ELSE, .ELSEIF, .ENDIF) that makes it easy for you to code multiway branching logic. They cause the assembler to generate CMP and conditional jump instructions in the background, which are shown in the listing file (.lst).

The syntax is shown on the right. The square brackets show that .ELSEIF and .ELSE are optional, whereas .IF and .ENDIF are required. A condition is a boolean expression involving the same operators used in C++ and Java. The expression is evaluated at runtime.
 .IF  condition1
    statements
 [.ELSEIF  condition2
    statements ]
 [.ELSE
    statements ]
 .ENDIF

The table below shows a complete list of relational and logical operators.

Operator Description
expr1 == expr2 Returns true when expr1 is equal to expr2.
expr1 != expr2 Returns true when expr1 is not equal to expr2.
expr1 > expr2 Returns true when expr1 is greater than expr2.
expr1 >= expr2 Returns true when expr1 is greater than or equal to expr2.
expr1 < expr2 Returns true when expr1 is less than expr2.
expr1 <= expr2 Returns true when expr1 is less than or equal to expr2.
!expr Returns true when expr is false.
expr1 && expr2 Performs logical AND between expr1 and expr2.
expr1 || expr2 Performs logical OR between expr1 and expr2.
expr1 & expr2 Performs bitwise AND between expr1 and expr2.
CARRY? Returns true if the Carry flag is set.
OVERFLOW? Returns true if the Overflow flag is set.
PARITY? Returns true if the Parity flag is set.
SIGN? Returns true if the SIGN flag is set.
ZERO? Returns true if the ZERO flag is set.