There is much
opcode overlap between the various flavors of
PIC processors.
This list is for the mid-range 14 bit 16CXX series. "14-bit?" you say? Yup.
PICs are
8 bit processors, but in its
Harvard Architecture you are jamming the opcode AND
data into a 14 bit word.
It works well: except for a few conditional statements, everything happens in one clock cycle.
Registers, conventions, etc:
W for the working register the all-purpose accumulator for the PIC
f for file register - any one of the register functions stored in memory as part of the register file
"number" or k for a constant or literal value
label for a label that identifies a constant or memory location
addlw number
- adds a number with the number in the working register.
addwf FileReg, f
- adds the number in the working register to the number in a
file register and puts the result in the file register.
addwf FileReg, w
- adds the number in the working register to the number in a
file register and puts the result back into the working register,
leaving the file register unchanged.
andlw number
- ANDs a number with the number in the working register,
leaving the result in the working reg.
andwf FileReg, f
- ANDs the number in the working register with the number
in a file register and puts the result in the file register
bcf FileReg, bit
- clears a bit in a file register -- i.e. makes the bit 0
bsf FileReg, bit
- sets a bit in a file register -- i.e. makes the bit 1
btfsc FileReg, bit
- tests a bit in a file register and skips the next instruction if
the result is clear (i.e. if that bit is 0). This is how IF/THEN
statements get coded: the next instruction (the one that is
conditionally skipped) is a goto/call statement to a routine for
that case. Smooth, huh? Also works with btfss and the
increment/decrement tests.
btfss FileReg, bit
- tests a bit in a file register and skips the next instruction if
the result is set (i.e. if that bit is 1).
call label
- makes the chip call a subroutine, after which you can
return to where you left off.
clrf FileReg
- clears (makes 0) the number in a file register.
clrw
- clears the working register.
clrwdt
- clears the watchdog timer.
comf FileReg, f
- complements (invert bits of) the number in a file register,
leaving the result in the file register.
decf FileReg, f
- decrements (subtracts one from) a file register and puts the
result in the same file register.
decfsz FileReg, f
- decrements a file register and if the result is zero it skips the
next instruction. The result is put in the file register.
goto label
- makes the program jump to label
incf FileReg, f
- increments (adds one to) a file register and puts the result in
the file register.
incfsz FileReg, f
- increments a file register and if the result is zero it skips the
next instruction.
iorlw number
- inclusive ORs a number with the number in the working
register.
iorwf FileReg, f
- inclusive ORs the number in the working register with the
number in a file register and puts the result in the file register.
movfw FileReg
movf FileReg, w
- moves (copies) the number in a file register to the working
register or vice-versa
movlw number
- moves (copies) a number into the working register.
movwf FileReg
- moves (copies) the number in the working register into a file register.
nop
- do nothing (useful for timing)
retfie
- returns from a subroutine and enables the Global Interrupt Enable bit.
retlw number
- returns from a subroutine with a particular number (literal) in
the working register. This is used for lookup tables.
return
- returns from a subroutine.
rlf FileReg, f
- rotates the bits in a file register to the left, putting the result in the file register.
rrf FileReg, f
- rotates the bits in a file register to the right, putting the result in the file register.
sleep
- sends the PIC to sleep, a lower power consumption mode.
It can be awakened by interrupts or a reset.
sublw number
- subtracts the number in the working register from a number.
subwf FileReg, f
- subtracts the number in the working register from the
number in a file register and puts the result in the file register.
Note that both of the subtract opcodes work exactly backwards from what you would think. Grrrr.
swapf FileReg, f
- swaps the two halves of the 8 bit binary number in a file
register, leaving the result in the file register.
tris PORTX
- uses the number in the working register to specify which bits
of a port are inputs (correspond to a binary 1) and which are
outputs (correspond to 0).
xorlw number
- XORs a number with the number in the working register.
xorwf FileReg, f
- XORs the number in the working register with the number in
a file register and puts the result in the file register.