Everything
5.1.6 Expression

A combination of numeric values, symbols, and operators can be written as an expression.

-

A space character or a tab can be inserted between an operator and a numeric value.

-

Multiple operators can be used in combination.

-

When using an expression as a symbol value, make sure that the value of the expression is determined at assembly.

-

A character constant must not be used as a term of an expression.

-

The expression value as a result of operation must be within the range from –2147483648 to 2147483647. The assembler does not check if the result is outside this range.

(a)

Operator

The following is a list of the operators that can be written in programs.

-

Unary operators

Table 5.7

Unary Operators

Operator

Function

+

Handles the value that follows the operator as a positive value.

-

Handles the value that follows the operator as a negative value.

~

Logically negates the value that follows the operator.

SIZEOF

Handles the size (bytes) of the section specified in the operand as a value.

TOPOF

Handles the start address of the section specified in the operand as a value.

Be sure to insert a space character or a tab between the operand and SIZEOF or TOPOF.

Example: SIZEOF program

-

Binary operators

Table 5.8

Binary Operators

Operator

Function

+

Adds the lvalue and rvalue.

-

Subtracts the rvalue from the lvalue.

*

Multiplies the lvalue and rvalue.

/

Divides the lvalue by the rvalue.

%

Obtains the remainder by dividing the lvalue by the rvalue.

>>

Shifts the lvalue to the right by the number of bits specified by the rvalue.

<<

Shifts the lvalue to the left by the number of bits specified by the rvalue.

&

Logically ANDs the lvalue and rvalue in bitwise.

|

Logically (inclusively) ORs the lvalue and rvalue in bitwise.

^

Exclusively ORs the lvalue and rvalue in bitwise.

-

Conditional operators

A conditional operator can be used only in the operand of the .IF or .ELIF directive.

Table 5.9

Conditional Operators

Operator

Function

>

Evaluates if the lvalue is greater than the rvalue.

<

Evaluates if the lvalue is smaller than the rvalue.

>=

Evaluates if the lvalue is equal to or greater than the rvalue.

<=

Evaluates if the lvalue is equal to or smaller than the rvalue.

==

Evaluates if the lvalue is equal to the rvalue.

!=

Evaluates if the lvalue is not equal to the rvalue.

-

Precedence designation operator

Table 5.10

Precedence Designation Operator

Operator

Function

()

An operation enclosed within ( ) takes precedence. If multiple pairs of parentheses are used in an expression, the left pair is given precedence over the right pair. Parentheses can be nested.

(b)

Order of Expression Evaluation

The expression in an operand is evaluated in accordance with the following precedence and the resultant value is handled as the operand value.

-

The operators are evaluated in the order of their precedence. The operator precedence is shown in the following table.

-

Operators having the same precedence are evaluated from left to right.

-

An operation enclosed within parentheses takes the highest precedence.

Table 5.11

Order of Expression Evaluation

Precedence

Operator Type

Operator

1

Precedence designation operator

()

2

Unary operator

+, -, ~, SIZEOF, TOPOF

3

Binary operator 1

*, /, %

4

Binary operator 2

+, -

5

Binary operator 3

>>, <<

6

Binary operator 4

&

7

Binary operator 5

|, ^

8

Conditional operator

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