A term is the smallest element that the assembler parser can recognize when processing an expression. Each term has a value and a type. An expression is formed by one or more terms. The assembler evaluates each expression into a single value, and uses that value as an operand. Each expression also has a type. If an expression is formed by one term, the expression has the same type as the type of the term. If an expression consists of more than one term, the type is determined by the expression handler according to certain rules applied to all the types of terms contained in the expression. Expression types are important because:
AIX 4.3 adds an additional aspect to assemly language expressions: that of the object mode and relocation vs. the size of the data value being calculated. In 32-bit mode, relocation is applied to 32-bit quantities; expressions resulting in a requirement for relocation (for example, a reference to an external symbol) can not have their value stored in any storage area other than a word. As the 4.3 assembler has added the .llong pseudo-op, it is worthwhile to point out that expressions used to initialize the contents of a .llong may not require relocation. In 64-bit mode, relocation is applied to double-word quantities. Thus, expression results that require relocation can not have their value stored in a location smaller than a double-word.
Arithmetic evaluations of expressions in 32-bit mode is consistent with the behavior found in prior releases of the assembler. Integer constants are considered to be 32-bit quantities, and the calculations are 32-bit calculations. In 64-bit mode constants are 64-bit values, and expressions are evaluated using 64-bit calculations.
The following is a list of all the types of terms and an abbreviated name for each type:
A term is absolute if its value does not change upon program relocation. In other words, a term is absolute if its value is independent of any possible code relocation operation.
An absolute term is one of the following items:
The value of an absolute term is the constant value.
A term is relocatable if its value changes upon program relocation. The value of a relocatable term depends on the location of the control section containing it. If the control section moves to a different storage location (for example, a csect is relocated by the binder at bind time), the value of the relocatable term changes accordingly.
A relocatable term is one of the following items:
If it is not used as a displacement for a D-form instruction, the value of a csect label or a location counter reference is its relocatable address, which is the sum of the containing csect address and the offset relative to the containing csect. If it is used as a displacement for a D-form instruction, the assembler implicitly subtracts the containing csect address so that only the the offset is used for the displacement. A csect address is the offset relative to the beginning of the first csect of the file.
A dsect is a reference control section that allows you to describe the layout of data in a storage area without actually reserving any storage. A dsect provides a symbolic format that is empty of data. The assembler does assign location counter values to the labels that are defined in a dsect. The values are the offsets relative to the beginning of the dsect. The data in a dsect at run time can be referenced symbolically by using the labels defined in a dsect.
Relocatable terms based on a dsect location counter (either the dsect name or dsect labels) are meaningful only in the context of a .using statement. Since this is the only way to associate a base address with a dsect, the addressability of the dsect is established in combination with the storage area.
A relocatable term may be based on any control section, either csect or dsect, in all the contexts except if it is used as a relocatable address constant. If a csect label is used as an address constant, it represents a relocatable address, and its value is the offset relative to the csect plus the address of the csect. A dsect label cannot be used as a relocatable address constant since a dsect is only a data template and has no address.
If two dsect labels are defined in the same dsect, their difference can be used as an absolute address constant.
A term is external relocatable (E_EXT ) if it is an external symbol (a symbol not defined, but declared within the current module, or defined in the current module and globally visible), a csect name, or a TOC entry name.
This term is relocatable because its value will change if it, or its containing control section, is relocated.
An external relocatable term or expression cannot be used as the operand of a .set pseudo-op.
An external relocatable term is one of the following items:
Except for the undefined symbol, if this term is not used as a displacement for a D-form instruction, its value is its relocatable address, which is the offset relative to the begining of the first csect in the file. If it is used as a displacement for a D-form instruction, the assembler implicitly subtracts the containing csect address (except for a TOC entry name), usually producing a zero displacement because the csect address is subtracted from itself. If a TOC entry name is used as a displacement for a D-form instruction, the assembler implicitly subtracts the address of the TOC anchor, so the offset relative to the TOC anchor is the displacement.
An undefined symbol cannot be used as a displacement for a D-form instruction. In other cases, its value is zero.
A term is TOC-relative relocatable (E_TREL ) if it is a label contained within the TOC.
This type of term is relocatable since its value will change if the TOC is relocated.
A TOC-relative relocatable term is one of the following items:
If this term is not used as a displacement for a D-form instruction, its value is its relocatable addresss, which is the sum of the offset relative to the TOC and the TOC anchor address. If it is used as a displacement for a D-form instruction, the assembler implicitly subtracts the TOC anchor address, so the offset relative to the TOC anchor is the displacement.
A term has TOCOF relocatable (E_TOCOF ) type if it is the first operand of a .tocof pseudo-op.
This type of term has a value of zero. It cannot be used as a displacement for a D-form instruction. It cannot participate in any arithmetic operation.
Expressions can have all the types that terms can have. An expression with only one term has the same type as its term. Expressions can also have restricted external relocatable (E_REXT ) type, which a term cannot have because this type requires at least two terms.
An expression has restricted external relocatable (E_REXT ) type if it contains two relocatable terms that are defined in different control sections (terms not meeting the requirements for paired relocatable terms, as defined in "Expression Type of Combined Expressions") and have opposite signs.
The following are examples of combinations of relocatable terms that produce an expression with restricted external relocatable type:
The value assigned to an expression of this type is based on the results of the assembler arithmetic evaluation of the values of its terms. When participating in an arithmetic operation, the value of a term is its relocatable address.
Terms within an expression can be combined with binary operators. Also, a term can begin with one or more unary operators. The assembler expression handler evaluates and determines the resultant expression type, value, and relocation table entries.
The following rules apply when calculating a value:
The assembler applies the following rules when determining the requirements for object file relocation table entries for an exression.
The assembler applies the following rules when determining the type of a combined expression.
The following operators belong to group #1:
Operators in group #1 have the following rules:
The following operators belong to group # 2:
Operators in group # 2 have the following rules:
The following definitions will be used in later discussion:
|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_RE L term. A E_REXT term cannot be paired with any term.
|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:
|Conditions for Expression to have Type
|Relocation Table Entries
|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.
|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.
|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.
|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.
|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
The atof subroutine.
The .comm pseudo-op, .csect pseudo-op, .double pseudo-op, .dsect pseudo-op, .float pseudo-op, .lcomm pseudo-op, .tc pseudo-op, .toc pseudo-op, .tocof pseudo-op.