C operators and PIC instructions
All the following instructions, shown with their C equivalent,
set bits of the STATUS
file register.
C | PIC | |
---|---|---|
binary | = | MOV |
+ | ADD | |
- | SUB and SUBR | |
& | AND | |
| | IOR | |
^ | XOR | |
<< | SL | |
>> | LSR for unsignedASR for signed | |
unary | - | NEG |
~ | COM | |
++ | INC | |
-- | DEC |
C’s signed >>
uses ASR
.
Java’s >>
resembles ASR
and its >>>
resembles LSR
.
PIC status register
The PIC status register contains five flags, or bits, that can be set my PIC operations.
C
: Set when a carry occursZ
: Set when the result is zeroN
: Set when the result is negative, msb of 1OV
: Set when an overflow occursDC
: Set when a digit carry occurs in the 4 lsb bits
In general, all five bits are set by the addition, subtraction, increment, and decrement instructions. For subtraction, the carry bit is set as if the minuend is added to the twos complement of the subtrahend.
The bit-wise instructions and the MOV where a file register
is the source set the N
and Z
bits.
All shift instructions set the N
and Z
bits.
Some shift instructions also set the C
bits.
Take a look a the MSU ECE 3724 chapter 4 notes to see how the bits of the status register are used for shift operators and common control structures.