3.5. Numbers and Expressions

Numbers can be expressed in binary, octal, decimal, or hexadecimal. Binary numbers may be prefixed with a "%" symbol or suffixed with a "b" or "B". Octal numbers may be prefixed with "@" or suffixed with "Q", "q", "O", or "o". Hexadecimal numbers may be prefixed with "$", "0x" or "0X", or suffixed with "H". No prefix or suffix is required for decimal numbers but they can be prefixed with "&" if desired. Any constant which begins with a letter must be expressed with the correct prefix base identifier or be prefixed with a 0. Thus hexadecimal FF would have to be written either 0FFH or $FF. Numbers are not case sensitive.

A symbol may appear at any point where a number is acceptable. The special symbol "*" can be used to represent the starting address of the current source line within expressions.

The ASCII value of a character can be included by prefixing it with a single quote ('). The ASCII values of two characters can be included by prefixing the characters with a quote (").

LWASM supports the following basic binary operators: +, -, *, /, and %. These represent addition, subtraction, multiplication, division, and modulus. It also supports unary negation and unary 1's complement (- and ^ respectively). It is also possible to use ~ for the unary 1's complement operator. For completeness, a unary positive (+) is supported though it is a no-op. LWASM also supports using |, &, and ^ for bitwise or, bitwise and, and bitwise exclusive or respectively.

Operator precedence follows the usual rules. Multiplication, division, and modulus take precedence over addition and subtraction. Unary operators take precedence over binary operators. Bitwise operators are lower precdence than addition and subtraction. To force a specific order of evaluation, parentheses can be used in the usual manner.

As of LWASM 2.5, the operators && and || are recognized for boolean and and boolean or respectively. They will return either 0 or 1 (false or true). They have the lowest precedence of all the binary operators.