5.1.14 Restrictions on operations

The operation of an expression is performed by connecting terms with operator(s). Elements that can be described as terms are constants, names and labels. Each term has a relocation attribute.

Depending on the types of relocation attribute inherent in each term, operators that can work on the term are limited. Therefore, when describing an expression it is important to pay attention to the relocation attribute of each term constituting the expression.

(1)

Operators and relocation attributes

Each term constituting an expression has a relocation attribute.

If terms are categorized by relocation attribute, they can be divided into 2 types: absolute terms and relocatable terms.

The following table shows the types of relocation attributes and their properties, and also the corresponding terms.

Table 5.7

Relocation Attribute Types

Type

Property

Corresponding Elements

Absolute term

Term that is a value or constant determined at assembly time

-

Constants

-

Names for which constants are defined

Relocatable term

Term with a value that is not determined at assembly time

-

Labels

-

Names for which labels are defined

-

Labels defined with .EXTERN directive

-

Names defined with .EXTBIT directive

-

Symbols not defined in the module

 

The following tables categorize combinations of operators and terms which can be used in expressions by relocation attribute.

Table 5.8

Combinations of Operators and Terms by Relocation Attribute

Operator Type

Relocation Attribute of Term

X:ABS

Y:ABS

X:ABS

Y:REL

X:REL

Y:ABS

X:REL

Y:REL

+ X

A

A

R

R

- X

A

A

-

-

~ X

A

A

-

-

HIGH X

A

A

RNote 1

RNote 1

LOW X

A

A

RNote 1

RNote 1

HIGHW X

A

A

RNote 1

RNote 1

LOWW X

A

A

RNote 1

RNote 1

MIRHW X

A

A

RNote 2

RNote 2

MIRLW X

A

A

RNote 2

RNote 2

SMRLW X

A

A

RNote 2

RNote 2

DATAPOS X.Y

-

-

-

-

BITPOS X.Y

-

-

-

-

DATAPOS X

A

A

-

-

BITPOS X

A

A

-

-

X + Y

A

R

R

-

X - Y

A

-

R

R

X * Y

A

-

-

-

X / Y

A

-

-

-

X % Y

A

-

-

-

X >> Y

A

-

-

-

X << Y

A

-

-

-

X & Y

A

-

-

-

X | Y

A

-

-

-

X ^ Y

A

-

-

-

X == Y

A

-

-

-

X != Y

A

-

-

-

X > Y

A

-

-

-

X >= Y

A

-

-

-

X < Y

A

-

-

-

X <= Y

A

-

-

-

X && Y

A

-

-

-

X || Y

A

-

-

-

 

ABS : Absolute term

REL : Relocatable term

A : Result is absolute term

R : Result is relocatable term

- : Operation not possible

Note 1.

Operation is possible when X is not relocatable terms operated on by MIRHW, MIRLW, SMRLW, or DATAPOS.

Note 2.

Operation is possible when X is not relocatable terms operated on by HIGH, LOW, HIGHW, LOWW, MIRHW, MIRLW, SMRLW, or DATAPOS.

(2)

Nesting of operators

The HIGH, HIGHW, LOW, and LOWW operators can be specified in a nested manner.

(3)

Absolute expression and relative expression

Expressions are classified into absolute and relative expressions, which are handled separately.

(a)

Absolute expression

An expression indicating a constant is called an "absolute expression". An absolute expression can be used when an operand is specified for an instruction or when a value etc. is specified for a directive. An absolute expression usually consists of a constant or symbol. The following format is treated as an absolute expression.

<1>

Constant expression

If a reference to a previously defined symbol is specified, it is assumed that the constant of the value defined for the symbol has been specified. Therefore, a defined symbol reference can be used in a constant expression.

However, a symbol that is not defined or whose value is not determined when the symbol is referenced is not handled as a constant expression

Example

SYM1    .EQU    0x10        ;Define symbol SYM1
        MOV     A, #SYM1    ;SYM1, already defined, is treated as a constant
                             expression.

<2>

Symbol

The expressions related to symbols are the following ("±" is either "+" or "-").

-

Symbol

-

Symbol ± constant expression

-

Symbol - symbol

-

Symbol - symbol ± constant expression

 

A "symbol" here means a symbol that is an absolute term (a name for which a constant is defined somewhere in the module) but that is not defined or whose value is not determined yet when it is referenced.. If a reference to a previously defined symbol is specified, it is assumed that the "constant" of the value defined for the symbol has been specified.

Example

        MOV     A, #SYM1        --SYM1 is an undefined symbol at this point
SYM1    .EQU    0x10            --Defines SYM1

(b)

Relative expressions

An expression indicating an offset from a specific addressNote 1 is called a "relative expression". A relative expression is used to specify an operand by an instruction or to specify a value by data definition directive. A relative expression usually consists of a symbol (label and external reference name).

The following formatNote 2 is treated as an relative expression("±" is either "+" or "-").

Note 1.

This address is determined when the optimizing linker is executed. Therefore, the value of this offset may also be determined when the optimizing linker is executed.

Note 2.

It can regard an expression in the format of "-symbol + label reference", as being an expression in the format of "label reference - symbol," but it cannot regard an expression in the format of "label reference - (+symbol)" as being an expression in the format of "label reference - symbol". Therefore, use parentheses "( )" only in constant expressions.

 

-

Symbol

-

Symbol ± constant expression

-

Symbol - symbolNote

-

Symbol - symbol ± constant expressionNote

Note

A label cannot be used as a symbol after "-", except for subtraction between labels.

 

When any of the specified symbols is a relocatable term, the expression is handled as a relative expression. Here is an example of a relative expression.

Example

SIZE    .EQU    0x10
        MOV     A, #label1
        MOV     A, #label1 + 0x10
        MOV     A, #label2 ? SIZE
        MOV     A, #label2 ? SIZE + 0x10