SPRU513Y August 2001 – June 2022 SM320F28335-EP
The operands of a mathematical or logical operator must be well-defined expressions. That is, you must use the correct number of operands and the operation must make sense. For example, you cannot take the XOR of a floating-point value. In addition, well-defined expressions contain only symbols or assembly-time constants that have been defined before they occur in the directive's expression.
Three main factors influence the order of expression evaluation:
Parentheses | Expressions enclosed in parentheses are always evaluated first. 8 / (4 / 2) = 4, but 8 / 4 / 2 = 1 You cannot substitute braces ( { } ) or brackets ( [ ] ) for parentheses. |
Precedence groups | Operators, listed in Table 5-6, are divided into nine precedence groups. When parentheses do not
determine the order of expression evaluation, the highest precedence
operation is evaluated first. 8 + 4 / 2 = 10 (4 / 2 is evaluated first) |
Left-to-right evaluation | When
parentheses and precedence groups do not determine the order of
expression evaluation, the expressions are evaluated from left to
right, except for Group 1, which is evaluated from right to left. 8 / 4*2 = 4, but 8 / (4*2) = 1 |
Table 5-6 lists the operators that can be used in expressions, according to precedence group.
Group(1) | Operator | Description(2) |
---|---|---|
1 | + - ~ ! | Unary plus Unary minus 1s complement Logical NOT |
2 | * / % | Multiplication Division Modulo |
3 | + - | Addition Subtraction |
4 | << >> | Shift left Shift right |
5 | < <= > >= | Less than Less than or equal to Greater than Greater than or equal to |
6 | =[=] != | Equal to Not equal to |
7 | & | Bitwise AND |
8 | ^ | Bitwise exclusive OR (XOR) |
9 | | | Bitwise OR |
The assembler checks for overflow and underflow conditions when arithmetic operations are performed during assembly. It issues a warning (the "value truncated" message) whenever an overflow or underflow occurs. The assembler does not check for overflow or underflow in multiplication.