PICkit™ 3 Starter Kit User’s Guide
DS41628B-page 48 2012 Microchip Technology Inc.
In assembly, this is the most common instruction. Data is typically moved into WREG,
where operations can be performed or moved into another register.
3.3.5.1.2 movwf
Similar to movlw, data is moved from WREG to another register.
EXAMPLE 3-7:
3.3.5.1.3 decfsz
Use this to decrement a register by one. If the register is ‘0’ after decrementing, then
the next instruction is skipped. This is useful for delay loops.
3.3.5.1.4 bra/goto
These two instructions are used to jump to a new section of code. A (BRA) is a relative
jump from where the program counter is currently at. For the enhanced core, the coun-
ter can access -256≤n≤255 locations in program memory. The PIC18 BRA can access
-1024≤n≤1023 locations in program memory. Notice how the value is signed. A branch
is nice since it can jump across page boundaries on the enhanced mid-range core.
The goto is an unconditional jump and can access every location in the current page
on the enhanced mid-range. The PIC18 can access all program memory with a goto.
The downside of this is that it requires two words of programming memory. This means
that each goto instruction in PIC18 requires twice as much space than the BRA.
In PIC18, when the destination is within 1024 program locations, a relative should be
used instead of a GOTO. In enhanced mid-range, the relative branch offers an advan-
tage only when crossing back and forth between pages.
3.3.5.2 PIC18
3.3.5.2.1 BTG
This will invert the value of a bit in the target register.
3.3.6 Assembly
3.3.6.1 ENHANCED MID-RANGE
EXAMPLE 3-8:
TABLE 3-6: NEW INSTRUCTIONS FOR PIC18
Instruction English Purpose
btg Toggle Bit Blink LED
movwf OPTION_REG
Before Instruction:
OPTION_REG = 0xFF
W = 0x4F
After Instruction:
OPTION_REG = 0x4F
W = 0x4F
movlw b'00111000' ;set cpu clock speed
movwf OSCCON