PIC18 cheatsheet

SUBLW

Detailed reference for the SUBLW instruction in PIC18 ISA.

Description

Subtract the contents of WREG from an 8‑bit literal constant k. The result is written back to WREG.

  • Operation: WREG = k - WREG.
  • Status bits (C, Z, DC, OV) are updated as with any 8‑bit subtraction. The result is always stored to WREG regardless of flags.

Examples

; From literal, WREG=5, literal=10 → W=5
MOVLW 0x05
SUBLW 0x0A
; Underflow, WREG=2, literal=0 → W=0xFE
MOVLW 0x02
SUBLW 0x00
; Borrow across the high byte, WREG=0xFF, literal=0x80 → W=0x81
MOVLW 0xFF
SUBLW 0x80
; Zero result, WREG=0, literal=0 → W=0
MOVLW 0x00
SUBLW 0x00
; Literal pre‑load then subtract, result in W
MOVLW 0x12
SUBLW 0x20   ; W = 0x20 - 0x12 = 0x0E