Operators are used in expressions. The value of the expression is determined at assembly time and does not change when the program runs.
Operators should not be confused with processor instructions. The reserved word ADD is an instruction. The plus sign (+) is an operator. For example, Amount+2 is a valid use of the plus operator (+); it tells the assembler to add 2 to Amount, which might be a value or an address. This operation, which occurs at assembly time, is different from the ADD instruction, which tells the processor to perform addition at run time.
The assembler evaluates expressions that contain more than one operator according to the following rules:
Operations in parentheses are always performed before any adjacent operations.
Binary operations of highest precedence are performed first.
Operations of equal precedence are performed from left to right.
Unary operations of equal precedence are performed right to left.
The order of precedence for all operators is listed in Table 1.3. Operators on the same line have equal precedence.
Table 1.3 Operator Precedence
Precedence | Operators |
1 | (), [] |
2 | LENGTH, SIZE, WIDTH, MASK |
3 | . (structure-field-name operator) |
4 | : (segment-override operator), PTR |
5 | LROFFSET, OFFSET, SEG, THIS, TYPE |
6 | HIGH, HIGHWORD, LOW, LOWWORD |
7 | +,– (unary) |
8 | *, /, MOD, SHL, SHR |
9 | +, – (binary) |
10 | EQ, NE, LT, LE, GT, GE |
11 | NOT |
12 | AND |
13 | OR, XOR |
14 | OPATTR, SHORT, .TYPE |