Combining expressions with group 2 operators
The assembler applies the rule of combining expressions with Group 2 operators.
The following operators belong to group # 2:
- +, -
Operators in group # 2 have the following rules:
- <E_ABS> <op2> <E_ABS> ==> E_ABS
- <E_ABS> <op2> <E_REXT> ==> E_REXT
- <E_REXT> <op2> <E_ABS> ==> E_REXT
- <E_ABS> <op2> <E_TOCOF> ==> an error
- <E_TOCOF> <op2> <E_ABS> ==> an error
- <non E_ABS> <op2> <E_REXT> ==> an error
- <E_REXT> <op2> < non E_ABS> ==> an error
- <E_ABS> - <E_TREL> ==> an error
- Unary + and - are treated the same as the binary operators with absolute value 0 (zero) as the left term.
- Other situations where one of the terms is not an absolute expression require more complex rules.
The following definitions will be used in later discussion:
Item | Description |
---|---|
paired relocatable terms | Have opposite signs and are defined in the same section. The value represented by paired relocatable terms is absolute. The result type for paired relocatable terms is E_ABS. Paired relocatable terms are not required to be contiguous in an expression. Two relocatable terms cannot be paired if they are not defined in the same section. A E_TREL term can be paired with another E_TREL term or E_EXT term, but cannot be paired with a E_REL term (because they will never be in the same section). A E_EXT or E_REL term can be paired with another E_EXT or E_REL term. A E_REXT term cannot be paired with any term. |
opposite terms | Have opposite signs and point to the same symbol table entry. Any term can have its opposite term. The value represented by opposite terms is zero. The result type for opposite terms is almost identical to E_ABS, except that a relocation table entry (RLD) with a type R_REF is generated when it is used for data definition. Opposite terms are not required to be contiguous in an expression. |
The main difference between opposite terms and paired relocatable terms is that paired relocatable terms do not have to point to the same table entry, although they must be defined in the same section.
In the following example L1 and -L1 are
opposite terms ; and L1 and -L2 are paired relocatable
terms.
.file "f1.s"
.csect Dummy[PR]
L1: ai 10, 20, 30
L2: ai 11, 21, 30
br
.csect A[RW]
.long L1 - L1
.long L1 - L2
The following table shows rules for determining the type of complex combined expressions:
Item | Description | |
---|---|---|
Type | Conditions for Expression to have Type | Relocation Table Entries |
E_ABS | All the terms of the expression are paired relocatable terms, opposite terms, and absolute terms. | An RLD with type R_REF is generated for each opposite term. |
E_REXT | The expression contains two unpaired relocatable terms with opposite signs in addition to all the paired relocatable terms, opposite terms, and absolute terms. | Two RLDs, one with a type of R_POS and one with a type of R_NEG,
are generated for the unpaired relocatable terms. In addition, an
RLD with a type of R_REF is generated for each opposite term. If one term has a thread-local storage-mapping class and the other does not, an error is reported. |
E_REL, E_EXT | The expression contains only one unpaired E_REL or E_RXT term in addition to all the paired relocatable terms, opposite terms, and absolute terms. | If the expression is used in a data definition, one RLD with type R_POS or R_NEG will be generated. In addition, an RLD with type R_REF is generated for each opposite term. |
E_TREL | The expression contains only one unpaired E_TREL term in addition to all the paired relocatable terms, opposite terms, and absolute terms. | If the expression is used as a displacement in a D-form instruction, one RLD with type R_TOC will be generated, otherwise one RLD with type R_POS or R_NEG will be generated. In addition, an RLD with type R_REF is generated for each opposite term. |
Error | If the expression contains more than two unpaired relocatable terms, or it contains two unpaired relocatable terms with the same sign, an error is reported. |
The following example illustrates the preceding table:
.file "f1.s"
.csect A[PR]
L1: ai 10, 20, 30
L2: ai 10, 20, 30
EL1: l 10, 20(20)
.extern EL1
.extern EL2
EL2: l 10, 20(20)
.csect B[PR]
BL1: l 10, 20(20)
BL2: l 10, 20(20)
ba 16 + EL2 - L2 + L1 # Result is E_REL
l 10, 16+EL2-L2+L1(20) # No RLD
.csect C[RW]
BL3: .long BL2 - B[PR] # Result is E_ABS
.long BL2 - (L1 - L1) # Result is E_REL
.long 14-(-EL2+BL1) + BL1 - (L2-L1) # Result is E_REL
.long 14 + EL2 - BL1 - L2 + L1 # Result is E_REL
.long (B[PR] -A[PR]) + 32 # Result is E_REXT