PIC18 cheatsheet

ANDWF

Detailed reference for the ANDWF instruction in PIC18 ISA.

Description

AND the contents of WREG with file register f.

  • d = 0 → result is stored in WREG.
  • d = 1 → result is stored back into register f.
  • a = 0 → Access‑bank addressing.
  • a = 1 → Banked addressing.

Examples

; d=0, a=0  → result in WREG, Access bank
ANDWF 0x21, 0, 0   ; W = 0x21 & W
; d=0, a=1  → result in WREG, Banked address
ANDWF 0x21, 0, 1   ; W = 0x21 & W
; d=1, a=0  → result back to file register, Access bank
ANDWF 0x21, 1, 0   ; 0x21 = 0x21 & W
; d=1, a=1  → result back to file register, Banked address
ANDWF 0x21, 1, 1   ; 0x21 = 0x21 & W
; Load literal into WREG then AND, result in WREG (Access bank)
MOVLW 0x0F
ANDWF 0x21, 0, 0   ; W = 0x21 & 0x0F