Expressions

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

Operands

The following operands can be used:

Operators

The Assembler supports a number of operators which are described here. The higher the precedence, the higher the priority. Expressions may be enclosed in parentheses, and such expressions are always evaluated before combined with anything outside the parentheses.

The following operators are defined:
 
Symbol Description
! Logical Not
~ Bitwise Not
- Unary Minus
* Multiplication
/ Division
+ Addition
- Subtraction
<< Shift left
>> Shift right
< Less than
<= Less than or equal
> Greater than
>= Greater than or equal
== Equal
!= Not equal
& Bitwise And
^ Bitwise Xor
| Bitwise Or
&& Logical And
|| Logical Or

Logical Not

Symbol:        !
Description:   Unary operator which returns 1 if the expression was zero, and returns 0 if the expression was nonzero
Precedence:    14
Example:       ldi r16,!0xf0  ; Load r16 with 0x00

Bitwise Not

Symbol:       ~
Description: Unary operator which returns the input expression with all bits inverted
Precedence:  14
Example:     ldi r16,~0xf0  ; Load r16 with 0x0f

Unary Minus

Symbol:      -
Description: Unary operator which returns the arithmetic negation of an expression
Precedence:  14
Example:     ldi r16,-2  ; Load -2(0xfe) in r16

Multiplication

Symbol:      *
Description: Binary operator which returns the product of two expressions
Precedence:  13
Example:     ldi r30,label*2 ; Load r30 with label*2

Division

Symbol:      /
Description: Binary operator which returns the integer quotient of the left expression divided by the right expression
Precedence:  13
Example:     ldi r30,label/2 ; Load r30 with label/2

Addition

Symbol:      +
Description: Binary operator which returns the sum of two expressions
Precedence:  12
Example:     ldi r30,c1+c2  ; Load r30 with c1+c2

Subtraction

Symbol:      -
Description: Binary operator which returns the left expression minus the right expression
Precedence:  12
Example:     ldi r17,c1-c2  ;Load r17 with c1-c2

Shift left

Symbol:      <<
Description: Binary operator which returns the left expression shifted left the number given by the right expression
Precedence:  11
Example:     ldi r17,1<<bitmask  ;Load r17 with 1 shifted left bitmask times

Shift right

Symbol:      >>
Description: Binary operator which returns the left expression shifted right the number given by the right expression
Precedence:  11
Example:     ldi r17,c1>>c2  ;Load r17 with c1 shifted right c2 times

Less than

Symbol:      <
Description: Binary operator which returns 1 if the signed expression to the left is Less than the signed expression to the right, 0 otherwise
Precedence:  10
Example:     ori r18,bitmask*(c1<c2)+1  ;Or r18 with an expression
 

Less or equal

Symbol:      <=
Description: Binary operator which returns 1 if the signed expression to the left is Less than or Equal to the signed expression to the right, 0 otherwise
Precedence:  10
Example:     ori r18,bitmask*(c1<=c2)+1 ;Or r18 with an expression

Greater than

Symbol:      >
Description: Binary operator which returns 1 if the signed expression to the left is Greater than the signed expression to the right, 0 otherwise
 Precedence: 10
 Example:    ori r18,bitmask*(c1>c2)+1  ;Or r18 with an expression

Greater or equal

Symbol:      >=
Description: Binary operator which returns 1 if the signed expression to the left is Greater than or Equal to the signed expression to the right, 0 otherwise
Precedence:  10
Example:     ori r18,bitmask*(c1>=c2)+1 ;Or r18 with an expression

Equal

Symbol:      ==
Description: Binary operator which returns 1 if the signed expression to the left is Equal to the signed expression to the right, 0 otherwise
Precedence:  9
Example:     andi r19,bitmask*(c1==c2)+1 ;And r19 with an expression

Not equal

Symbol:      !=
Description: Binary operator which returns 1 if the signed expression to the left is Not Equal to the signed expression to the right, 0 otherwise
Precedence:  9
Example:     .SET flag=(c1!=c2)  ;Set flag to 1 or 0

Bitwise And

Symbol:      &
Description: Binary operator which returns the bitwise And between two expressions
Precedence:  8
Example:     ldi r18,High(c1&c2) ;Load r18 with an expression

Bitwise Xor

Symbol:      ^
Description: Binary operator which returns the bitwise Exclusive Or between two expressions
Precedence:  7
Example:     ldi r18,Low(c1^c2) ;Load r18 with an expression

Bitwise Or

Symbol:      |
Description: Binary operator which returns the bitwise Or between two expressions
Precedence:  6
Example:     ldi r18,Low(c1|c2) ;Load r18 with an expression

Logical And

Symbol:      &&
Description: Binary operator which returns 1 if the expressions are both nonzero, 0 otherwise
Precedence:  5
Example:     ldi r18,Low(c1&&c2)  ;Load r18 with an expression

Logical Or

Symbol:      ||
Description: Binary operator which returns 1 if one or both of the expressions are nonzero, 0 otherwise
Precedence:  4
Example:     ldi r18,Low(c1||c2)  ;Load r18 with an expression

Functions

The following functions are defined: