Expressions

This section discusses the expressions used in coding operand entries for source statements. You can use an expression to specify:

Expressions have absolute and relocatable values. Whether an expression is absolute or relocatable depends on the value of the terms it contains. The assembler evaluates relocatable and absolute expressions at assembly time. Figure 10 shows examples of valid expressions.

In addition to expressions used in coding operand entries, there are three types of expression that you can use only in conditional assembly instructions: arithmetic, logical, and character expressions. They are evaluated during conditional assembly. For more information, see Assigning values to SET symbols.

An expression is composed of a single term or an arithmetic combination of terms. The assembler reduces multiterm expressions to single values. Thus, you do not have to compute these values yourself. The following are examples of valid expressions:

Figure 10. Examples of valid expressions
*                                     BETA*10
AREA1+X'2D'                           B'101'
*+32                                  C'ABC'
N-25                                  29
FIELD+332                             L'FIELD
FIELD                                 LAMBDA+GAMMA
(EXIT-ENTRY+1)+GO                     TEN/TWO
ALPHA-BETA/(10+AREA*L'FIELD)-100      =F'1234'
=A(100,133,175,221)+8

Rules for coding expressions

The rules for coding an absolute or relocatable expression are:

Figure 11 shows the definitions of absolute and relocatable expressions.

Figure 11. Definitions of absolute and relocatable expressions
*-----------*
|           |
|Absolute   |
|Expression |
|           |
*-----*-----*
      |
      V Can be any of
      *-------------*-------------*-------------*-------------*-------------*-------------*-------------*-------------*
      |             |             |             |             |             |             |             |             |
      V             V             V             V             V             V             V             V             V
*-----*-----* *-----*-----* *-----*-----* *-----*-----* *-----*-----* *-----*-----* *-----*-----* *-----*-----* *-----*-----*
|           | |           | |           | |           | |           | |           | |           | |           | |           |
| Rel. Exp. | | Absolute  | | Abs. Exp. | | Abs. Exp. | | Abs. Exp. | | Abs. Exp. | |(Abs. Exp.)| | +Abs. Exp.| | -Abs. Exp.|
|     -     | | Term      | |     +     | |     -     | |     *     | |     /     | |           | | ^         | | ^         |
| Rel. Exp. | |           | | Abs. Exp. | | Abs. Exp. | | Abs. Exp. | | Abs. Exp. | |           | | |         | | |         |
*-----*-----* *-----*-----* *-----------* *-----------* *-----------* *-----------* *-----------* *-+---------* *-+---------*
      |             |                                                                               *------*------*
      |             V Can be any of                                                                        |
      |             *-------------*-------------*-------------*-------------*                          unary operators
      |             |             |             |             |             |
      |             V             V             V             V             V
      |       *-----*-----* *-----*-----* *-----*-----* *-----*-----* *-----*-----*
      |       |Absolute   | | Self-     | | Symbol    | | Symbol    | | Symbol    |
      |       |Valued     | | Defining  | | Length    | | Integer   | | Scale     |
      |       |Ordinary   | | Term      | | Attribute | | Attribute | | Attribute |
      |       |Symbol     | |           | |           | |           | |           |
      |       *-----------* *-----------* *-----------* *-----------* *-----------*
      |
      V
*-----*-----*
|           |
|Relocatable|
|Expression |
|           |
*-----*-----*
      |
      V Can be any of
      *-------------*-------------*-------------*-------------*-------------*
      |             |             |             |             |             |
      V             V             V             V             V             V
*-----*-----* *-----*-----* *-----*-----* *-----*-----* *-----*-----* *-----*-----*           Operators Allowed
|           | |           | |           | |           | |           | |           |
|Relocatable| | Rel. Exp. | | Rel. Exp. | |(Rel. Exp.)| |+Rel. Exp. | |-Rel. Exp. |           Unary:  + Positive
|Term       | |     +     | |     -     | |           | |^          | |^          |                   - Negative
|           | | Abs. Exp. | | Abs. Exp. | |           | ||          | ||          |
*-----*-----* *-----------* *-----------* *-----------* *+----------* *+----------*           Binary: + Addition
      |                                                  |             |                              - Subtraction
      |                                                  *------*------*                              * Multiplication
      V Can be any of                                           |                                     / Division
      *-------------*                                    unary operators
      |             |
      V             V
*-----*-----* *-----*-----*
|Relocatable| | Location  |                                                                   Rel. Exp. = Relocatable Expression
|Valued     | | Counter   |                                                                   Abs. Exp. = Absolute Expression
|Ordinary   | | Reference |
|Symbol     | |           |
*-----------* *-----------*

Evaluation of expressions

A single-term expression, like 29 or BETA, has the value of the term involved. The assembler reduces a multiterm expression, like 25*10+A/B or BETA+10, to a single value, as follows:

  1. It evaluates each term.
  2. It does arithmetic operations from left to right. However:
    1. It does unary operations before binary operations.
    2. It does binary operations of multiplication and division before the binary operations of addition and subtraction.
  3. In division, it gives an integer result; any fractional portion is dropped. Division by zero gives 0.
  4. In parenthesized expressions, the assembler evaluates the innermost expressions first and then considers them as terms in the next outer level of expressions. It continues this process until the outermost expression is evaluated.
  5. A term or expression's intermediate value and computed result must lie in the range of -231 through +231-1.

The assembler evaluates paired relocatable terms at each level of expression nesting.

Absolute and relocatable expressions

An expression is absolute if its value is unaffected by program relocation. An expression is relocatable if its value depends upon program relocation. The two types of expressions, absolute and relocatable, take on these characteristics from the term or terms composing them. A description of the factors that determine whether an expression is absolute or relocatable follows.

Absolute expression

An absolute expression is one whose value remains the same after program relocation. The value of an absolute expression is called an absolute value.

An expression is absolute, and is reduced to a single absolute value if the expression:

  1. Comprises a symbol with an absolute value, a self-defining term, or a symbol length attribute reference, or any arithmetic combination of absolute terms.

    The absolute terms may include Integer and Scale attributes, but not Type attributes.

  2. Contains relocatable terms alone or in combination with absolute terms, and if all these relocatable terms are paired.
Relocatability attribute

The relocatability attribute describes the attribute of a relocatable term. If a pair of terms are defined in the same control section, they are characterized as having the same relocatability attribute.

If the terms are defined in different control sections, or have different relocatability attributes, the expression is said to be "complex relocatable".

The relocatability attribute is the same as the ESDID for external symbols, and the "Relocation ID" in the listing.

Paired relocatable terms

An expression can be absolute even though it contains relocatable terms, provided that all the relocatable terms are paired. The pairing of relocatable terms cancels the effect of relocation.

The assembler reduces paired terms to single absolute terms in the intermediate stages of evaluation. The assembler considers relocatable terms as paired under the following conditions:

The following examples show absolute expressions. A is an absolute term; X and Y are relocatable terms with the same relocatability:

A-Y+X
A
A*A
X-Y+A
(*+*)-(*+*)
*-*

A reference to the location counter must be paired with another relocatable term from the same control section; that is, with the same relocatability. For example:

*-Y
Relocatable expression

A relocatable expression is one whose value changes by n if the origin of the control section in which it appears is relocated n bytes.

A relocatable expression can be a single relocatable term. The assembler reduces a relocatable expression to a single relocatable value if the expression:

  1. Is composed of a single relocatable term, or
  2. Contains relocatable terms, alone or in combination with absolute terms, and
    1. All the relocatable terms but one are paired. Note that the unpaired term gives the expression a relocatable value; the paired relocatable terms and other absolute terms constitute increments or decrements to the value of the unpaired term.
    2. The relocatability attribute of the whole expression is that of the unpaired term.
    3. The sign preceding the unpaired relocatable term must be positive, after all unary operators have resolved.

The following examples show relocatable expressions. A is an absolute term, W and X are relocatable terms with the same relocatability attribute, and Y is a relocatable term with a different relocatability attribute.

Y-32*A                      W-X+*     =F'1234' (literal)
* (reference to             W-X+W     Y
  location counter)         W-X+Y     A*A+W-W+Y
Complex relocatable expressions

Complex relocatable expressions, unlike relocatable expressions, can contain:

Using the same symbols, the following are examples of complex relocatable expressions:

    W+X                 *+*
    X-Y                 A-W+Y

Complex relocatable expressions are used in A-type and Y-type address constants to generate address constant values. For more details, refer to "Complex relocatable expressions", and Address constants--A and Y. V-type and S-type constants may not contain complex relocatable expressions. You can assign a complex relocatable value to a symbol using the EQU instruction, as described on page EQU instruction.


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