PIC18 cheatsheet

SUBWFB

Detailed reference for the SUBWFB instruction in PIC18 ISA.

Description

Subtract WREG from file register f with borrow.

  • d = 0 → result stored in WREG.
  • d = 1 → result stored back into register f.
  • a = 0 → Access‑bank addressing.
  • a = 1 → Banked addressing.
  • The borrow is taken from the Carry flag; if C is cleared an extra 1 is subtracted.

Examples

; d=0, a=0  → result in WREG, Access bank
SUBWFB 0x30, 0, 0   ; W = 0x30 - W - borrow
; d=0, a=1  → result in WREG, Banked address
SUBWFB 0x30, 0, 1   ; W = 0x30 - W - borrow
; d=1, a=0  → result back to f, Access bank
SUBWFB 0x30, 1, 0   ; 0x30 = 0x30 - W - borrow
; d=1, a=1  → result back to f, Banked address
SUBWFB 0x30, 1, 1   ; 0x30 = 0x30 - W - borrow
; Load literal into WREG then subtract, result in WREG (Access bank)
MOVLW 0x10
SUBWFB 0x30, 0, 0   ; W = 0x30 - 0x10 - borrow