Everything
5.1.2 Expressions and operators

An expression is a symbol, constant, an operator combined with one of the above, or a combination of operators.

Elements of an expression other than the operators are called terms, and are referred to as the 1st term, 2nd term, and so forth from left to right, in the order that they occur in the expression.

The assembler supports the operators shown in "Table 5.3 Operator Types". Operators have priority levels, which determine when they are applied in the calculation. The priority order is shown in "Table 5.4 Operator Precedence Levels".

The order of calculation can be changed by enclosing terms and operators in parentheses "( )".

Example

mov32   5 * (SYM + 1), r12

 

In the above example, "5 * (SYM+1)" is an expression. "5" is the 1st term, "SYM" is the 2nd term, and "1" is the 3rd term. The operators are "*", "+", and "( )".

Table 5.3

Operator Types

 

The above operators can also be divided into unary operators and binary operators.

Unary operators

+sign, -sign, !, HIGH, LOW, HIGHW, LOWW, HIGHW1

Binary operators

+, -, *, /, %, &, |, ^, ==, =, >, >=, <, <=, >>, <<, &&, ||

Table 5.4

Operator Precedence Levels

Priority

Level

Operators

Higher

 

 

 

 

 

 

 

Lower

1

+sign, -sign, !, HIGH,LOW,HIGHW,HIGHW1,LOWW,STARTOF,SIZEOF

2

*, /, %, >>, <<

3

&, |, ^

4

+, -

5

==, !=, >, >=, <, <=

6

&&, ||

 

Expressions are operated according to the following rules.

-

The order of operation is determined by the priority level of the operators.
When two operators have the same priority level, operation proceeds from left to right, except in the case of unary operators, where it proceeds from right to left.

-

Sub-expressions in parentheses "( )" are operated before sub-expressions outside parentheses.

-

Expressions are operated using unsigned 32-bit values. However, terms of expressions in multiplication, division, and modulo operation and the second term of logical shift are handled as signed 32-bit values.

-

If the value of a constant exceeds 32 bits, the overflow value is ignored.

-

In division, the decimal fraction part is discarded.
If the divisor is 0, an error occurs.

-

Negative values are represented as two's complement.

-

Relative expressions are evaluated as 0 at the time when the source is assembled (the evaluation value is determined at link time).

Table 5.5

Evaluation examples

Expression

Evaluation

2 + 4 * 5

22

(2 + 3) * 4

20

10/4

2

0 - 1

0xFFFFFFFF

EXTNote + 1

0

Note

EXT: External reference symbols