IF - Conditional assembly

Syntax
  IF <condition>

  
    [<assembly language statements>]

  
  [ELSE]

  
    [<assembly language statements>]

  
  ENDIF

  
Synonym
None
Description

If <condition> is true, the statements immediately following the IF directive are assembled. Assembly continues until the corresponding ELSE or ENDIF directive is reached. Then all the statements until the corresponding ENDIF directive are ignored. Nesting of conditional blocks is allowed. The maximum level of nesting is limited by the available memory at assembly time.

The expected syntax for <condition> is:

  <condition> := <expression> <relation> <expression>

  
  <relation>  := =|!=|>=|>|<=|<|<>

  

The <expression> must be absolute (It must be known at assembly time).

Example

The following listing is an example of the use of conditional assembly directives

Listing: IF and ENDIF

Try: EQU   0

     IF Try != 0

       LD D6,#100


     ELSE

       LD D6,#0


     ENDIF

The value of Try determines the instruction to be assembled in the program. As shown, the LD D6,#0 instruction is assembled. Changing the operand of the EQU directive to one causes the LD D6,#100 instruction to be assembled instead. The following shows the listing provided by the Assembler for these lines of code:

Listing: Output listing after conditional assembly

    1    1          0000 0000   Try: EQU   0
    2    2          0000 0000        IF Try != 0

    4    4                           ELSE

    5    5   000000 A600             
LD D6,#0

    6    6                           ENDIF