4.7 Expressions and Operators

Expressions can consist of unary operators (one operand, e.g., not) or binary operators (two operands, e.g., +). The operators allowable in expressions are listed in the table below.

Operators within expressions are evaluated left to right, thus the expression 5 + 1 * 2 will yield the value 12. Use parenthesis to change the order of operator execution, for example 5 + (1 * 2) will yield the value 7.

With the exception of the equality (e.g. =) and relational operators (e.g. >=), all the operators listed can be freely combined in both constant and relocatable expressions. Relocatable expressions will be evaluated by the linker at link time, after psects have been positioned and symbol values have been determined.

Table 4-5. Assembly Operators
OperatorPurposeExample
*multiplicationmovlw 4*33,w
+additionbra $+1
-subtractionDB 5-2
/divisionmovlw 100/4
= or eqequalityIF inp eq 66
> or gtsigned greater thanIF inp > 40
>= or gesigned greater than or equal toIF inp ge 66
< or ltsigned less thanIF inp < 40
<= or lesigned less than or equal toIF inp le 66
<> or nesigned not equal toIF inp <> 40
lowlow byte of operandmovlw low(inp)
highhigh byte of operandmovlw high(1008h)
highwordhigh 16 bits of operandDW highword(inp)
modmodulusmovlw 77mod4
& or andbitwise ANDclrf inp&0ffh
^bitwise XOR (exclusive or)movf inp^80,w
|bitwise ORmovf inp|1,w
notbitwise complementmovlw not 055h,w
<< or shlshift leftDB inp>>8
>> or shrshift rightmovlw inp shr 2,w
rolrotate leftDB inp rol 1
rorrotate rightDB inp ror 1
float2424-bit version of real operandDW float24(3.3)
nultests if macro argument is null