Detailed reference for the SWAPF instruction in PIC18 ISA.
Swap the upper and lower 4‑bit nibbles of the 8‑bit file register f.
f.d = 0 → the swapped value is stored in WREG.d = 1 → the swapped value overwrites the original contents of register f.a (access‑bank) bit for SWAPF; the file register address can refer to any location.; d=0 → result goes into WREG (Access bank example)
SWAPF 0x20, 0 ; W = 0xBA (if 0x20 originally contains 0xAB); d=0 → result goes into WREG (Access bank example)
SWAPF 0x20, 0 ; W = 0xBA (if 0x20 originally contains 0xAB); d=1 → result written back to file register
SWAPF 0x20, 1 ; 0x20 = 0xBA (if 0x20 originally contains 0xAB); d=1 → result written back to file register
SWAPF 0x20, 1 ; 0x20 = 0xBA (if 0x20 originally contains 0xAB); Preload WREG with a literal, then d=0 → WREG is overwritten by swapped value
MOVLW 0x10
SWAPF 0x20, 0 ; W = 0xBA (ignores previous WREG value); Preload WREG with a literal, then d=0 → WREG is overwritten by swapped value
MOVLW 0x10
SWAPF 0x20, 0 ; W = 0xBA (ignores previous WREG value)