www.riscos.com Technical Support: |
|
Expressions are combinations of simple values, unary and binary operators, and brackets. There is a strict order of precedence in their evaluation: expressions in brackets are evaluated first, then operators are applied in precedence order. Adjacent unary operators evaluate from right to left; binary operators of equal precedence are evaluated from left to right.
The assembler includes an extensive set of operators for use in expressions, many of which resemble their counterparts in high-level languages.
Unary operators have the highest precedence (bind most tightly) so are evaluated first. A unary operator precedes its operand, and adjacent operators are evaluated from right to left.
Binary operators are written between the pair of sub-expressions on which they operate. Operators of equal precedence are evaluated in left to right order. The binary operators are presented below in groups of equal precedence, in decreasing precedence order.
These are the binary operators which bind most tightly and have the highest precedence:
Operator | Usage | Explanation |
---|---|---|
* | A*B | Multiply |
/ | A/B | Divide |
MOD | A:MOD:B | A modulo B |
These operators act only on numeric expressions.
Operator | Usage | Explanation |
---|---|---|
LEFT | A:LEFT:B | The leftmost B characters of A |
RIGHT | A:RIGHT:B | The rightmost B characters of A |
CC | A:CC:B | B concatenated on to the end of A |
In the two slicing operators LEFT and RIGHT, A must be a string and B must be a numeric expression.
Operator | Usage | Explanation |
---|---|---|
ROL | A:ROL:B | Rotate A left B bits |
ROR | A:ROR:B | Rotate A right B bits |
SHL | A:SHL:B | Shift A left B bits |
SHR | A:SHR:B | Shift A right B bits |
The shift operators act on numeric expressions, shifting or rotating the first operand by the amount specified by the second. Note that SHR is a logical shift and does not propagate the sign bit.
Operator | Usage | Explanation |
---|---|---|
AND | A:AND:B | Bitwise AND of A and B |
OR | A:OR:B | Bitwise OR of A and B |
EOR | A:EOR:B | Bitwise Exclusive OR of A and B |
+ | A+B | Add A to B |
- | A-B | Subtract B from A |
The bitwise operators act on numeric expressions. The operation is performed independently on each bit of the operands to produce the result.
The relational operators act upon two operands of the same type to produce a logical value. Allowable types of operand are numeric, program-relative, register-relative, and strings. Strings are sorted using ASCII ordering. String A will be less than string B if it is either a leading substring of string B, or if the left-most character of A in which the two strings differ is less than the corresponding character in string B. Note that arithmetic values are unsigned, so the value of
0>-1 is {FALSE}.
These are the weakest binding operators with the lowest precedence.
Operator | Usage | Explanation |
---|---|---|
LAND | A:LAND:B | Logical AND of A and B |
LOR | A:LOR:B | Logical OR of A and B |
LEOR | A:LEOR:B | Logical Exclusive OR of A and B |
The Boolean operators perform the standard logical operations on their operands, which should evaluate to {TRUE} or {FALSE}.