XORWF Logic
Bitwise exclusive OR of W and a file register.
| Syntax | XORWF f, d |
|---|---|
| Operands | f: register address 0-127 (bank bits come from STATUS); d: 0 or w puts the result in W, 1 or f puts it back in f |
| Operation | (W) XOR (f) → destination |
| Status bits | Z |
| Words / cycles | 1 word, 1 cycle |
| Encoding | 00 0110 dfff ffff |
How it works
XORWF flips the bits of register f that are 1 in W. Because x XOR x = 0, it also compares: Z is set when W and f are equal.
Example
; XORWF example from picsimulator.com/instructions/xorwf.html
list p=16f84a
include <p16f84a.inc>
org 0
movlw 0xFF
movwf 0x20
movlw 0x0F
xorwf 0x20, f ; 0x20 = 0xF0: the low nibble is flipped
The four low bits flip from 1 to 0.
Open this example in the simulator
Watch out for
- Toggling a port pin with XORWF PORTx reads the pins, not the latch. If a pin is loaded or still changing, read-modify-write can flip the wrong value; keep a copy of the port in RAM if that matters.