Expressions

Expressions are very powerful in the assembler. The following operators are
allowed (in order of precedence):

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.

Watch out for the parenthesis. The command:ld a, (3*5)+1
will result in an error, because the parser recognizes "ld a,(". Then
it will parse until the ")", and find some junk: "+1". A workaround for such a
situation is to prefix the expression with "0+".

Labels in expressions

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:

The argument of org.

The argument of seek.

The first argument of ds.

The argument of if.

Literals

Literals are also quite flexible. The following literals can be
distinguished:

By default, all numbers are decimal. Number ending on "d" are decimal even if they start with a 0.

Numbers which start with a "0" are octal, as are numbers ending on "o" or "q".

Numbers starting with "0x", "$", or "&h" are hexadecimal, as are numbers ending on "h".

Numbers starting with a "%" or "&b" are binary, as are numbers ending on "b".

Numbers starting with a "@" are variable base numbers, see below.

The special value "$" is the address of the first byte of the current
command.

Characters may be used within single quotes. Usual C escapes are allowed:

\t is tab (9)

\r is carriage return (13)

\n is newline (10)

\a is alert (7)

Any other character (including ') is used unchanged.

Variable base numbers

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