a?b:c | Ternary operator, as in C. |
a|b | Bitwise or. |
a^b | Bitwise xor. |
a&b | Bitwise and. |
a==b and a!=b | Equality. |
a<b and a>b and a<=b and a>=b | Inequality. |
a<<b and a>>b | Bitshifts. |
a+b and a-b | Binary addition and subtraction. |
a*b and a/b and a%b | Multiply, divide and modulo. |
~a and +a and -a | Bitwise not and negation. |
(a) | Parenthesis. |
number or label | Literals. |
ld a, (3*5)+1
Expression evaluation is a very complex part of the assembler. The implementation tries to allow everything which is possible. This is done in the following way: In all expressions, labels can be used. When an expression is encountered, it is computed. If the computation fails, it is scheduled to be computed at the end of assembling, when all label values are known. If a label is assigned a value (with equ), and the computation fails, it is put in a different queue. Recomputation is tried every time the label is used. If it fails, then the expression using the label also fails. This way labels may be defined in terms of other labels which are defined later. Recursive definitions are not allowed.
There are some expressions however, which must be calculated at the moment they occur, usually because the address of the next command depends on them. Those expressions are:
Literals are also quite flexible. The following literals can be distinguished:
Numbers can be specified in any base (radix) from 2 to 37. To use this, the number should start with a "@". The first character after the "@" defines the radix of the number. After that (and optional whitespace), the number itself is specified.
The radix defining character is the expression "10 - 1", in the desired base, so it is the highest digit that can be used in that base. After 9, letters a-z follow. For example, to write a hexadecimal number, it is possible to use "@f 1c", which is the same as "0x1c".