 # Expressions and operators

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

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.

Operator Usage Explanation
? ?A Number of bytes generated by line defining label A.
BASE
INDEX
:BASE:A
:INDEX:A
If A is a PC-relative or register-relative expression then BASE returns the number of its register component, and INDEX the offset from that base register.

BASE and INDEX are most likely to be of use within macros.

LEN :LEN:A Length of string A
CHR :CHR:A ASCII string of A
STR :STR:A Hexadecimal string of A. STR returns an eight-digit hexadecimal string corresponding to a numeric expression, or the string T or F if used on a logical expression.
+ +A Unary plus
- -A Unary negate.

+ and - can act on numeric, program-relative and string expressions.

NOT :NOT:A Bitwise complement of A
LNOT :LNOT:A Logical complement of A
DEF :DEF:A {TRUE} if A is defined, otherwise {FALSE}

#### Binary operators

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.

##### Multiplicative operators

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.

##### String manipulation operators
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.

##### Shift operators
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.

##### Addition and logical operators
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.

##### Relational operators
Operator Usage Explanation
= A=B A equal to B
> A>B A greater than B
>= A>=B A greater than or equal to B
< A<B A less than B
<= A<=B A less than or equal to B
/= A/=B A not equal to B
<> A<>B A not equal to B

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}.

##### Boolean operators

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}.

This edition Copyright © 3QD Developments Ltd 2015
Last Edit: Tue,03 Nov 2015