PIC18 cheatsheet

DECFSZ

Detailed reference for the DECFSZ instruction in PIC18 ISA.

Description

Decrement the contents of file register f by one.

  • The resulting value is either written back to f or to WREG depending on the d option.
  • If the decrement result is zero, the processor skips the following instruction.
  • d = 0 → store result in WREG.
  • d = 1 → store result back into file register f.
  • a = 0 → use Access‑bank addressing for f.
  • a = 1 → use Banked addressing for f.
DECFSZ f, [d], [a]

Examples

; d=0, a=0  → result in WREG, Access bank
DECFSZ 0x20, 0, 0   ; W = 0x20-1, skip if result is 0
; d=0, a=1  → result in WREG, Banked addressing
DECFSZ 0x20, 0, 1   ; W = 0x20-1, skip if result is 0
; d=1, a=0  → result back to file register, Access bank
DECFSZ 0x20, 1, 0   ; 0x20 = 0x20-1, skip if result is 0
; d=1, a=1  → result back to file register, Banked addressing
DECFSZ 0x20, 1, 1   ; 0x20 = 0x20-1, skip if result is 0
; Load literal into WREG then decrement (result stored in WREG, Access bank)
MOVLW 0x10
DECFSZ 0x20, 0, 0   ; W = 0x20-1, skip if result is 0