Arithmetic Operators and Precedence
Arithmatic operators and their precedence are listed in Table: Arithmetic Operators and Precedence.
Selected operators are discussed in greater detail in subsections following the table.
Table: Arithmetic Operators and Precedence
Operator
|
Example
|
$
|
Current/Return program counter
|
goto $ + 3
|
(
|
Left Parenthesis
|
1 + (d * 4)
|
)
|
Right Parenthesis
|
(Length + 1) * 256
|
!
|
Item NOT (logical complement)
|
if ! (a == b)
|
-
|
Negation (2's complement)
|
-1 * Length
|
~
|
Complement
|
flags = ~flags
|
high
|
Return high byte
|
movlw high CTR_Table
|
low
|
Return low byte
|
movlw low CTR_Table
|
upper
|
Return upper byte
|
movlw upper CTR_Table
|
*
|
Multiply
|
a = b * c
|
/
|
Divide
|
a = b / c
|
%
|
Modulus
|
entry_len = tot_len % 16
|
+
|
Add
|
tot_len = entry_len * 8 + 1
|
-
|
Subtract
|
entry_len = (tot - 1) / 8
|
<<
|
Left shift
|
flags = flags << 1
|
>>
|
Right shift
|
flags = flags >> 1
|
>=
|
Greater or equal
|
if entry_idx >= num_entries
|
>
|
Greater than
|
if entry_idx > num_entries
|
<
|
Less than
|
if entry_idx < num_entries
|
<=
|
Less or equal
|
if entry_idx <= num_entries
|
==
|
Equal to
|
if entry_idx == num_entries
|
=
|
Not equal to
|
if entry_idx != num_entries
|
&
|
Bitwise AND
|
flags = flags & ERROR_BIT
|
^
|
Bitwise exclusive OR
|
flags = flags ^ ERROR_BIT
|
|
|
Bitwise inclusive OR
|
flags = flags | ERROR_BIT
|
&&
|
Logical AND
|
if (len == 512) && (b == c)
|
||
|
Logical OR
|
if (len == 512) || (b == c)
|
=
|
Set equal to
|
entry_index = 0
|
+=
|
Add to, set equal
|
entry_index += 1
|
-=
|
Subtract, set equal
|
entry_index -= 1
|
*=
|
Multiply, set equal
|
entry_index *= entry_length
|
/=
|
Divide, set equal
|
entry_total /= entry_length
|
%=
|
Modulus, set equal
|
entry_index %= 8
|
<<=
|
Left shift, set equal
|
flags <<= 3
|
>>=
|
Right shift, set equal
|
flags >>= 3
|
&=
|
AND, set equal
|
flags &= ERROR_FLAG
|
|=
|
Inclusive OR, set equal
|
flags |= ERROR_FLAG
|
^=
|
Exclusive OR, set equal
|
flags ^= ERROR_FLAG
|
++
|
Increment
|
i ++
|
- -
|
Decrement
|
i --
|
High/Low/Upper
Syntax
high <operand>
low <operand>
upper <operand>
Description
These operators are used to return one byte of a multi-byte label value. This is done to handle dynamic pointer calculations as might be used with table read and write instructions.
Example
movlw low size ; handle the lsb's
movpf wreg, low size_lo
movlw high size ; handle the msb's
movpf wreg, high size_hi
Increment/Decrement (++/--)
Syntax
<variable>++
<variable>--
Description
Increments or decrements a variable value. These operators can only be used on a line by themselves; they cannot be embedded within other expression evaluation.
Example
LoopCount = 4
while LoopCount > 0
rlf Reg, f
LoopCount --
endw