SETB instruction

Use the SETB instruction to assign a bit value to a SETB symbol. You can assign the bit values, 0 or 1, to a SETB symbol directly and use it as a switch.

If you specify a logical (Boolean) expression in the operand field, the assembler evaluates this expression to determine whether it is true or false, and then assigns the value 1 or 0, respectively, to the SETB symbol. You can use this computed value in condition tests or for substitution.

Read syntax diagramSkip visual syntax diagram>>-variable_symbol--SETB--binary_value-------------------------><
 
variable_symbol
is a variable symbol.

A global variable symbol in the name field must have been previously declared as a SETB symbol in a GBLB instruction. Local SETB symbols need not be declared in a LCLB instruction. The assembler considers any undeclared variable symbol found in the name field of a SETB instruction as a local SET symbol. The variable symbol is assigned a type attribute value of N.

binary_value
is a binary bit value that may be specified as:

Rules for Coding Logical Expressions: The following is a summary of coding rules for logical expressions:

Figure 41. Defining logical expressions
*-----------*
|           |
|Logical1   |
|Expression |
|           |
*-----*-----*
      |
      V Can be any of
      *-------------*-------------------------------------------------*               Logical Operators Allowed
      V             V                                                 V
*-----*-----* *-----*-----*-----------*-----------* *-----------*-----*-----*         OR      Intersection
|           | |           |  OR       |           | |           |           |         AND     Union
|  Logical2 | |Logical2   |  OR NOT   |  Logical  | |    NOT    |Logical2   |         NOT     Negation
|  Term     | |Expression |  AND      |  Term     | |           |Expression |         XOR     Exclusive OR
|           | |           |  AND NOT  |           | |           |           |
|           | |           |  XOR      |           | |           |           |
|           | |           |  XOR NOT  |           | |           |           |
*-----*-----* *-----------*-----------*-----------* *-----------*-----------*
      |
      V Can be any of
      *-------------*-------------*-------------*-------------*-------------*-------------*
      V             V             V             V             V             V             V
*-----*-----* *-----*-----* *-----*-----* *-----*-----* *-----*-----* *-----*-----* *-----*-----*
|           | | SETB2     | |           | |           | |           | | Predefined| |           |
| Logical2  | | Variable  | |Arithmetic2| |     02    | |     12    | | Absolute  | | Logical2  |
| Relation  | | Symbol    | |Value      | |           | |           | | Ordinary  | | Function  |
|           | |           | |           | |           | |           | | Symbol    | |           |
*-----*-----* *-----------* *-----------* *-----------* *-----------* *-----------* *-----------*
      |
      V Can be any of
      *-----------------------------------------*
      V                                         V
*-----*-----*                             *-----*-----*
|           |                             |           |
|Arithmetic |                             | Character |
|Relation   |                             | Relation  |
|           |                             |           |
*-----*-----*                             *-----*-----*
      |                                         |                                     Relational Operators Allowed
      V Which is                                V Which is
*-----*-----*-----------*-----------*     *-----*-----*-----------*-----------*       EQ      Equal
|           |  EQ, NE   |           |     |           |  EQ, NE   |           |       NE      Not equal
|Arithmetic |  LE, LT   |Arithmetic |     | Character3|  LE, LT   | Character3|       LE      Less than or equal
|Comparand  |  GE, GT   |Comparand  |     | Comparand |  GE, GT   | Comparand |       LT      Less than
|           |           |           |     |           |           |           |       GE      Greater than or equal
*-----*-----*-----------*-----------*     *-----*-----*-----------*-----------*       GT      Greater than
      |                                         |
      V Which can be                            V Can be any of
      |                                         *-------------*-------------*-----------------*
      |                                         V             V             V                 V
*-----*-----*                             *-----*-----* *-----*-----* *-----*----------* *-----*-----*
|           |                             |           | |           | | Type Attribute | |Character  |
|Arithmetic |                             |Character  | | Substring | | or Operation   | |Exp. and   |
|Expression |                             |Expression | | Notation  | | Code           | |Substring  |
|           |                             |           | |           | | Reference4     | |Notation   |
*-----------*                             *-----------* *-----------* *----------------* *-----------*
Notes:
  1. Outermost expression must be enclosed in parentheses in SETB and AIF instructions.
  2. Optional parentheses around terms and expressions at this level.
  3. Must be in the range 0 through 1024 characters.
  4. Must stand alone and not be enclosed in single quotation marks.

Subscripted SETB symbols

The SETB symbol in the name field can be subscripted. If the same SETB symbol has not been previously declared in a GBLB or LCLB instruction with an allowable dimension, then the symbol is implicitly declared as a local SETB array variable.

The assembler assigns the binary value explicitly specified, or implicit in the logical expression present in the operand field, to the position in the declared array given by the value of the subscript. The subscript expression must not be 0 or have a negative value.

Logical (SETB) expressions

You can use a logical expression to assign a binary value to a SETB symbol. You can also use a logical expression to represent the condition test in an AIF instruction. This use lets you code a logical expression whose value (0 or 1) varies according to the values substituted into the expression and thereby determine whether or not a branch is to be taken.

Figure 41 defines a logical expression.

It is important to note that logical expressions contain unquoted spaces that do not terminate the operand field. This is called "logical-expression format", and such expressions are always enclosed in parentheses.

A logical expression can consist of a logical expression and a logical term separated by a logical operator delimited by spaces. The logical operators are:

AND
Format: Logical-expression
Operands: Binary
Output: (bexpr1 AND bexpr2) has value 1, if each logical expression evaluates to 1, otherwise the value is 0.

Example

After the following statements &VAR contains the arithmetic value 0.

Name      Operation      Operand

&OP1      SETB           1
&OP2      SETB           0
&VAR      SETB           (&OP1 AND &OP2)
AND NOT
Format: Logical-expression
Operands: Binary
Output: The value of the second logical term is inverted, and the expression is evaluated as though the AND operator was specified.

Example

(1 AND NOT 0) is equivalent to (1 AND 1).

NOT
Format:
Logical-expression, function-invocation
Operands: Binary
Output: NOT(bexp) inverts the value of the logical expression.
OR
Format: Logical-expression
Operands: Binary
Output: (bexp1 OR bexp2) returns a value of 1, if either of the logical expressions contain or evaluate to 1. If they both contain or evaluate to 0 then the value is 0.
OR NOT
Format: Logical-expression
Operands: Binary
Output: (bexp1 OR NOT bexp2) inverts the value of the second logical term, and the expression is evaluated as though the OR operator was specified. For example, (1 OR NOT 1) is equivalent to (1 OR 0).
XOR
Format: Logical-expression
Operands: Binary
Output: (bexp1 XOR bexp2) evaluates to 1 if the logical expressions contain or evaluate to opposite bit values. If they both contain or evaluate to the same bit value, the result is 0.
XOR NOT
Format: Logical-expression
Operands: Binary
Output: (bexp1 XOR NOT bexp2) inverts the second logical term, and the expression is evaluated as though the XOR operator was specified.

Example (1 XOR NOT 1) is equivalent to (1 XOR 0).

Relational operators

Relational operators provide the means for comparing two items. A relational operator plus the items form a relation. An arithmetic relation is two arithmetic expressions separated by a relational operator, and a character relation is two character strings (for example, a character expression and a type attribute reference) separated by a relational operator.

The relational operators are:

EQ
equal
NE
not equal
LE
less than or equal
LT
less than
GE
greater than or equal
GT
greater than
Evaluation of logical expressions

The assembler evaluates logical expressions as follows:

  1. It evaluates each logical term, which is given a binary value of 0 or 1.
  2. If the logical term is an arithmetic or character relation, the assembler evaluates:
    1. The arithmetic or character expressions specified as values for comparison in these relations
    2. The arithmetic or character relation
    3. The logical term, which is the result of the relation. If the relation is true, the logical term it represents is given a value of 1; if the relation is false, the term is given a value of 0.

    The two comparands in a character relation are compared, character by character, according to binary (EBCDIC) representation of the characters. If two comparands in a relation have character values of unequal length, the assembler always takes the shorter character value to be less.

  3. The assembler carries out logical operations from left to right. However,
    1. It carries out logical NOTs before logical ANDs, ORs and XORs
    2. It carries out logical ANDs before logical ORs and XORs
    3. It carries out logical ORs before logical XORs
  4. In parenthesized logical expressions, the assembler evaluates the innermost expressions first, and then considers them as logical terms in the next outer level of expressions. It continues this process until it evaluates the outermost expression.
Using SETB symbols

The logical value assigned to a SETB symbol is used for the SETB symbol appearing in the operand field of an AIF instruction or another SETB instruction.

If a SETB symbol is used in the operand field of a SETA instruction, or in arithmetic relations in the operand fields of AIF and SETB instructions, the binary values 1 (true) and 0 (false) are converted to the arithmetic values 1 and 0, respectively.

If a SETB symbol is used in the operand field of a SETC instruction, in character relations in the operand fields of AIF and SETB instructions, or in any other statement, the binary values 1 (true) and 0 (false), are converted to the character values '1' and '0', respectively.

The following example illustrates these rules. It assumes that (L'&TO EQ 4) is true, and (S'&TO EQ 0) is false.

          MACRO
 &NAME    MOVE            &TO,&FROM
          LCLA            &A1
          LCLB            &B1,&B2
          LCLC            &C1
 &B1      SETB            (L'&TO EQ 4)        Statement 1
 &B2      SETB            (S'&TO EQ 0)        Statement 2
 &A1      SETA            &B1                 Statement 3
 &C1      SETC            '&B2'               Statement 4
          ST              2,SAVEAREA
          L               2,&FROM&A1
          ST              2,&TO&C1
          L               2,SAVEAREA
          MEND
 -------------------------------------------------------------------
 HERE     MOVE            FIELDA,FIELDB
 -------------------------------------------------------------------
+HERE ST             2,SAVEAREA
+    L               2,FIELDB1
+    ST              2,FIELDA0
+    L               2,SAVEAREA

Because the operand field of statement 1 is true, &B1 is assigned the binary value 1. Therefore, the arithmetic value +1 is substituted for &B1 in statement 3. Because the operand field of statement 2 is false, &B2 is assigned the binary value 0. Therefore, the character value 0 is substituted for &B2 in statement 4.


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