THE PIC INSTRUCTION SET
For low-end chips with only a small amount of program memory, you might choose to program in assembly language instead of C. Here we’re assuming that you’ve already done some assembly coding on a different processor and, for that reason, that you only need to learn about PIC specifics. You’ll easily be able to do that as a self-learning exercise, but a few words on the peculiarities of the PIC 16 series instruction set will, hopefully, help you get up to speed.
Higher-end PIC devices differ but the thing you’ll probably find surprising about PIC 16 series chips is that they don’t have any conditional branch instruction such as BRZ (Branch if Zero). Certainly the chips have the necessary status bits – specifically zero and carry bits – but a different method is used for conditional flow control.
There are four conditional flow control instructions, all of them causing the next instruction to be skipped depending on whether a condition is met. These are BTFSS and BTFSC, which execute a bit test followed by a skip on set or clear, respectively, and DECFSZ and INCSFSZ, which execute a decrement or increment, respectively, followed by a skip if the result is zero. In most cases, the instruction following the conditional instruction – the one that may or may not be skipped – will be an unconditional branch, with the result that a PIC 16 assembly program will be slightly more like the proverbial spaghetti code than assembly programs for most other processors.