The Assembler incorporates constant expressions. Expressions can consist of operands, operators and functions. All expressions are 64 bits internally.

## Operands

The following operands can be used:

## Operators

The following operators are defined:

## Logical Not

Example: ldi r16,!0xf0 ; Load r16 with 0x00

## Bitwise Not

Description: Unary operator which returns the input expression with all bits inverted

Example: ldi r16,~0xf0 ; Load r16 with 0x0f

## Unary Minus

Description: Unary operator which returns the arithmetic negation of an expression

Example: ldi r16,-2 ; Load -2(0xfe) in r16

## Multiplication

Description: Binary operator which returns the product of two expressions

Example: ldi r30,label*2 ; Load r30 with label*2

## Division

Example: ldi r30,label/2 ; Load r30 with label/2

## Modulo

Example: ldi r30,label%2 ; Load r30 with label%2

## Addition

Description: Binary operator which returns the sum of two expressions

Example: ldi r30,c1+c2 ; Load r30 with c1+c2

## Subtraction

Description: Binary operator which returns the left expression minus the right expression

Example: ldi r17,c1-c2 ;Load r17 with c1-c2

## Shift left

Example: ldi r17,1<<bitmask ;Load r17 with 1 shifted left bitmask times

## Shift right

Example: ldi r17,c1>>c2 ;Load r17 with c1 shifted right c2 times

## Less than

Example: ori r18,bitmask*(c1<c2)+1 ;Or r18 with an expression

## Less or equal

Example: ori r18,bitmask*(c1<=c2)+1 ;Or r18 with an expression

## Greater than

Example: ori r18,bitmask*(c1>c2)+1 ;Or r18 with an expression

## Greater or equal

Example: ori r18,bitmask*(c1>=c2)+1 ;Or r18 with an expression

## Equal

Example: andi r19,bitmask*(c1==c2)+1 ;And r19 with an expression

## Not equal

Example: .SET flag=(c1!=c2) ;Set flag to 1 or 0

## Bitwise And

Description: Binary operator which returns the bitwise And between two expressions

Example: ldi r18,High(c1&c2) ;Load r18 with an expression

## Bitwise Xor

Description: Binary operator which returns the bitwise Exclusive Or between two expressions

Example: ldi r18,Low(c1^c2) ;Load r18 with an expression

## Bitwise Or

Description: Binary operator which returns the bitwise Or between two expressions

Example: ldi r18,Low(c1|c2) ;Load r18 with an expression

## Logical And

Description: Binary operator which returns 1 if the expressions are both nonzero, 0 otherwise

Example: ldi r18,Low(c1&&c2) ;Load r18 with an expression

## Logical Or

Example: ldi r18,Low(c1||c2) ;Load r18 with an expression

## Conditional operator

Syntax: condtion? expression1 : expression2

Description: Ternary operator which returns expression1 if condition is true, expression2 otherwise.

## Functions

LOG2(expression) returns the integer part of log2(expression)

INT(expression) Truncates a floating point expression to integer (ie discards fractional part)

FRAC(expression) Extracts fractional part of a floating point expression (ie discards integer part).

Q7(expression) Converts a fractional floating point expression to a form suitable for the FMUL/FMULS/FMULSU instructions. (sign + 7-bit fraction)

Q15(expression) Converts a fractional floating point expression to a form suitable for the FMUL/FMULS/FMULSU instructions. (sign +15-bit fraction)

ABS() Returns the absolute value of a constant expression.

DEFINED(symbol) Returns true if symbolis previously defined using .equ/.set/.def directives. Normally used in conjunction with .if directives (.if defined(foo)), but may be used in any context. It differs from other functions in that parentheses around its argument are not required, and that it only makes sense to use a single symbol as argument.

STRLEN(string) returns the length of a string c+onstant, in bytes.