AIF instruction

Use the AIF instruction to branch according to the results of a condition test. You can thus alter the sequence in which source program statements or macro definition statements are processed by the assembler.

The AIF instruction also provides loop control for conditional assembly processing, which lets you control the sequence of statements to be generated.

It also lets you check for error conditions and thereby to branch to the appropriate MNOTE instruction to issue an error message.

Read syntax diagramSkip visual syntax diagram>>-+-----------------+--AIF------------------------------------->
   '-sequence_symbol-'       
 
>--(logical_expression)sequence_symbol-------------------------><
 
sequence_symbol
is a sequence symbol
logical_expression
is a logical expression (see Logical (SETB) expressions) the assembler evaluates during conditional assembly time to determine if it is true or false. If the expression is true (logical value=1), the statement named by the sequence symbol in the operand field is the next statement processed by the assembler. If the expression is false (logical value=0), the next sequential statement is processed by the assembler.

In the following example, the assembler branches to the label .OUT if &C = YES:

         AIF             ('&C' EQ 'YES').OUT
.ERROR   ANOP
         .
         .
         .
.OUT     ANOP

The sequence symbol in the operand field is a conditional assembly label that represents a statement number during conditional assembly processing. It is the number of the statement that is branched to if the logical expression preceding the sequence symbol is true.

The statement identified by the sequence symbol referred to in the AIF instruction can appear before or after the AIF instruction. However, the statement must appear within the local scope of the sequence symbol. Thus, the statement identified by the sequence symbol must appear:

You cannot branch from open code into a macro definition or between macro definitions, regardless of nested calls to other macro definitions.

The following macro definition generates the statements needed to move a fullword fixed-point number from one storage area to another. The statements are generated only if the type attribute of both storage areas is the letter F.

         MACRO
&N       MOVE            &T,&F
         AIF             (T'&T NE T'&F).END  Statement 1
         AIF             (T'&T NE 'F').END   Statement 2
&N       ST              2,SAVEAREA          Statement 3
         L               2,&F
         ST              2,&T
         L               2,SAVEAREA
.END     MEND                                Statement 4

The logical expression in the operand field of Statement 1 has the value true if the type attributes of the two macro instruction operands are not equal. If the type attributes are equal, the expression has the logical value false.

Therefore, if the type attributes are not equal, Statement 4 (the statement named by the sequence symbol .END) is the next statement processed by the assembler. If the type attributes are equal, Statement 2 (the next sequential statement) is processed.

The logical expression in the operand field of Statement 2 has the value true if the type attribute of the first macro instruction operand is not the letter F. If the type attribute is the letter F, the expression has the logical value false.

Therefore, if the type attribute is not the letter F, Statement 4 (the statement named by the sequence symbol .END) is the next statement processed by the assembler. If the type attribute is the letter F, Statement 3 (the next sequential statement) is processed.

Extended AIF instruction

The extended AIF instruction combines several successive AIF statements into one statement.

Read syntax diagramSkip visual syntax diagram>>-+-----------------+--AIF------------------------------------->
   '-sequence_symbol-'       
 
   .-,-----------------------------------.  
   V                                     |  
>----(logical_expression)sequence_symbol-+---------------------><
 
sequence_symbol
is a sequence symbol
logical_expression
is a logical expression the assembler evaluates during conditional assembly time to determine if it is true or false. If the expression is true (logical value=1), the statement named by the sequence symbol in the operand field is the next statement processed by the assembler. If the expression is false (logical value=0), the next logical expression is evaluated.

The extended AIF instruction is exactly equivalent to n successive AIF statements. The branch is taken to the first sequence symbol (scanning left to right) whose corresponding logical expression is true. If none of the logical expressions is true, no branch is taken.

Example:

                                                                Cont.
         AIF             ('&L'(&C,1) EQ '$').DOLR,                X
                         ('&L'(&C,1) EQ '#').POUND,               X
                         ('&L'(&C,1) EQ '@').AT,                  X
                         ('&L'(&C,1) EQ '=').EQUAL,               X
                         ('&L'(&C,1) EQ '(').LEFTPAR,             X
                         ('&L'(&C,1) EQ '+').PLUS,                X
                         ('&L'(&C,1) EQ '-').MINUS

This statement looks for the occurrence of a $, #, @, =, (, +, and -, in that order; and causes control to branch to .DOLR, .POUND, .AT, .EQUAL, .LEFTPAR, .PLUS, and .MINUS, respectively, if the string being examined contains any of these characters at the position designated by &C.

Alternative format for AIF instruction

The alternative statement format is allowed for extended AIF instructions. This format is illustrated in the above example.

AIFB--synonym of the AIF instruction

For compatibility with some earlier assemblers, High Level Assembler supports the AIFB symbolic operation code as a synonym of the AIF instruction. However, you should not use the AIFB instruction in new applications as support for it might be removed in the future.


[ Top of Page | Previous Page | Next Page | Contents | Index ]