Overview
Expressions allow you to compute values at assembly time using operators and operands. The assembler supports arithmetic operations, character literals, and special symbols.Simple expressions
Numeric literals
- Decimal
- Binary
- Registers
- Register pairs
Standard base-10 numbers:
Character literals
Single characters enclosed in single quotes are converted to their ASCII values:\n - Newline
\n - Newline
\t - Tab
\t - Tab
\a - Alert
\a - Alert
\d - Delete
\d - Delete
\\\\ - Backslash
\\\\ - Backslash
\' - Single quote
\' - Single quote
Labels and symbols
Labels represent addresses and can be used in expressions:Current address (*)
The * symbol represents the current program counter:
Binary operators
Addition (+)
Adds two expressions. The result type is the type of the first operand.
Subtraction (-)
Subtracts the second expression from the first. The result type is the type of the first operand.
Nibble extraction (@)
Extracts a specific 4-bit nibble from a number. The syntax is number@nibble_index where nibble 0 is the least significant nibble.
- The left operand must be a number type
- Returns an
error.nibble_from_non_numberif applied to non-numeric types - The right operand is the nibble index (0-based, up to 15 for 64-bit values)
The nibble extraction operator is useful for:
- Splitting multi-byte values
- Extracting specific bit fields
- Processing individual digits in BCD arithmetic
Expression types
Every expression has a type that determines how it can be used:- number
- register
- register_pair
- address
- condition
Generic numeric values:
Complex expressions
Expressions can combine operators, but are limited to 3 tokens (operand-operator-operand):The assembler parses expressions into a maximum of 3 tokens. For more complex calculations, use equates to build up the result step-by-step.
Type inference
Expression types are inferred based on:-
Special symbols:
*→addresslabel,→address
-
Suffix notation:
nR→registernP→register_pairnB→numbern?→condition
-
Character literals:
'c'→number
-
Plain numbers:
123→number
-
Binary operations:
addr + num→addressnum @ idx→number
Expression errors
Common expression-related errors:invalid_char_expr
invalid_char_expr
Character literal format is invalid (missing quotes or malformed).
unrecognized_escape_sequence
unrecognized_escape_sequence
Escape sequence is not one of the supported sequences.
unterminated_char_literal
unterminated_char_literal
Character literal missing closing quote.
nibble_from_non_number
nibble_from_non_number
Nibble extraction (@) used on non-numeric type.
wrong_number_of_sub_expressions
wrong_number_of_sub_expressions
Expression has too many or too few parts.
type_mismatch
type_mismatch
Expression result type doesn’t match expected argument type.