PIC18 cheatsheet

COMF

Detailed reference for the COMF instruction in PIC18 ISA.

Description

Complement the contents of file register f.

  • The instruction performs a bitwise logical negate (NOT) of register f.
  • The result is stored WREG if d = 0 or back into register f if d = 1.
  • The a = 0 option selects the Access Bank; a = 1 selects the Banked addressing mode.
  • The Z flag is set if the result is zero; the C flag remains unchanged.

Examples

; d=0, a=0  → result in WREG, Access bank
COMF 0x20, 0, 0 ; W = ~0x20
; d=0, a=1  → result in WREG, Banked address
COMF 0x20, 0, 1 ; W = ~0x20
; d=1, a=0  → result back to file register, Access bank
COMF 0x20, 1, 0 ; 0x20 = ~0x20
; d=1, a=1  → result back to file register, Banked address
COMF 0x20, 1, 1 ; 0x20 = ~0x20
; Load literal into WREG then complement, result in WREG (Access bank)
MOVLW 0x10
COMF 0x20, 0, 0 ; W = ~0x20