Program Structure

Expressions

Expressions produce either an absolute or a relocatable result. Any operation involving only absolute terms yields an absolute result. Relocatable terms are allowed only for the + and - operators. The legal combinations involving relocatable terms are shown in “Legal Combinations For Relocatable Terms” on page 30.

Table 2-10

 

Legal Combinations For Relocatable Terms

 

 

 

 

 

 

 

 

 

 

Operation

 

Result

 

 

 

 

 

 

 

 

 

Absolute + Relocatable

 

Relocatable

 

 

 

 

 

 

 

 

 

Relocatable + Absolute

 

Relocatable

 

 

 

 

 

 

 

 

 

Relocatable - Absolute

 

Relocatable

 

 

 

 

 

 

 

 

 

Relocatable - Relocatable (defined locally)

 

Absolute

 

 

 

 

 

 

 

 

For more information on the term relocatable, refer to “Assembler

 

 

Features” on page 15.

 

 

 

 

The combination “relocatable-relocatable+relocatable” is not permitted.

NOTE

 

 

 

For example, assume the symbols MONTH and YEAR are relocatable, and

 

 

 

 

JANUARY and FEBRUARY are absolute. The expressions MONTH+JANUARY

 

 

and MONTH+FEBRUARY-4are relocatable, while the expressions

 

 

YEAR-MONTHand FEBRUARY-4are absolute. The expression

 

 

MONTH+JANUARY*4 is also legal and produces a relocatable result,

 

 

because JANUARY*4 is evaluated first, producing an absolute

 

 

intermediate result that is added to MONTH. The expression MONTH+YEAR

 

 

is illegal, because the sum of two relocatable terms is not permitted.

Because all instructions are a single word in length, it is not possible to form a complete 32-bit address in a single instruction. Therefore, it is likely that the Assembler (or linker) may not be able to insert the final address of a symbol into the instruction as desired. For example, to load the contents of a word into a register, the following instruction could be used:

LDW START,%r2

Because LDW provides only 14 bits for the address of START, the Assembler or linker prints an error message if the address of START requires more than 14 bits. There are two instructions, LDIL and ADDIL, whose function is to form the left-most 21 bits of a 32-bit address. The succeeding instruction, by using the target of the LDIL or ADDIL as a

30

Chapter 2

Page 30
Image 30
HP UX Developer Tools manual Legal Combinations For Relocatable Terms Operation Result