PIC18 cheatsheet

CPFSGT

Detailed reference for the CPFSGT instruction in PIC18 ISA.

Description

Compare the contents of file register f with WREG. If WREG contains a value greater than that in f, the instruction immediately following the compare instruction is skipped. The instruction also updates the Status register: Z is set when the values are equal and C is set when WREG > f.

  • a = 0 → Access‑bank addressing.
  • a = 1 → Banked addressing.

Examples

; a=0, WREG < f, no skip
CPFSGT 0x10, 0 ; W = 0x05, f = 0x07 → Next instruction executes
; a=0, WREG > f, skip
CPFSGT 0x10, 0 ; W = 0x09, f = 0x07 → Next instruction is skipped
; a=1, WREG < f, no skip
CPFSGT 0x0100, 1 ; W = 0x15, f = 0x20 → Next instruction executes
; a=1, WREG > f, skip
CPFSGT 0x0100, 1 ; W = 0x25, f = 0x20 → Next instruction is skipped
; Load literal into WREG then compare, skip if greater
MOVLW 0x12
CPFSGT 0x10, 0 ; W = 0x12, f = 0x07 → Next instruction is skipped