Expressions

Full infix expression evaluation is supported (including use of paranthesis to change the order of evaluation).
	a + b * c
where a = 1, b = 2 and c = 3

would result in 7

	(a + b) * c
would result in 9

Here is a full list of XCASM operators and their associated priorities

Expressions can generate one of three results:

NOTE:
Labels and assembler variables that hold labels as values produce the address refered to by the label during expression evaluation. If the label is defined within a code or data section then its value is subject to change between assembler passes. This is because it is relocated during the second pass. Such expressions (those involving label arithmetic on relocated labels) do not normally cause problems since although the value has changed between passes, it is still correct relative to the start of the section for which it was defined. This is not true of an equated label since it always belongs to the constant section (which does not get relocated) and not the section in which it was defined.
e.g.

	.sect	code_sect
	.code

fred	goto	bert

jack	.equ	fred		; this will probably flag jack as being redefined
				; with a different value

jack2	.equ	$		; as would this
to get round this, use assembler variables
e.g.

	.sect	code_sect
	.code

fred	goto	bert

jack	.set	fred		; no problem now

jack2	.set	$		; no problem here either
An expression involving labels within the same section can produce a safe constant which can be equated to a constant label
e.g.

	.sect	code_sect
	.data

fred	.db	"hello world"

jack	.equ	$-fred		; this does not cause a problem since fred and
				; $ (used here) both belong to the same section
				; so when the section gets relocated the net
				; result is still the same difference i.e. the
				; constant jack (the length of the string) does
				; not change between assembler passes

Special Operator Behaviour

The '+' operator when applied to a string (left hand operand) and either a string or non string (right hand operand), will perform string concatination. When the '+' operator is applied to a non string (left hand operand) and either a string or non string (right hand operand), will perform arithmetic (2s complement binary) addition.

e.g.

var1	.set	100
var2	.set	"hello"

	.db	var1+var2
will produce
	.db	100+0
(when "hello" is coerced to a number, the value 0 is returned)
	.db	var2+var1
will produce
	.db	"hello100"
When strings are coerced to numbers only those characters at the start of the string that coresspond to a valid number are used. In the case of a decimal number this must be any of the digits 1 to 9, in the case of an octal number this must be the digit 0 and in the case of a hex number this must be the character pair 0x. The '$' character may not be used in a string to indicate a hex number.
e.g.
	"12abc456"	is coerced to the interger value 12
	"124abc56"	is coerced to the interger value 124
	"a124bc56"	is coerced to the interger value 0
	""		is coerced to the interger value 0
	"0.76"		is coerced to the interger value 0
	"0xD"		is coerced to the interger value 13
	"$D"		is coerced to the interger value 0
	"076"		is coerced to the interger value 62