MOVF Data Movement
Copy a file register to W, or test it for zero by moving it onto itself.
| Syntax | MOVF 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 | (f) → destination |
| Status bits | Z |
| Words / cycles | 1 word, 1 cycle |
| Encoding | 00 1000 dfff ffff |
How it works
MOVF reads register f. With d = 0 (W) the value goes into W; with d = 1 (f) it is written back to the same register, which leaves it unchanged.
Either way, Z is set if the value is zero. MOVF f, F is the standard way to test a register for zero without disturbing W.
Example
; MOVF example from picsimulator.com/instructions/movf.html
list p=16f84a
include <p16f84a.inc>
org 0
movlw 0x42
movwf 0x20
clrw ; W = 0
movf 0x20, w ; W = 0x42
movf 0x20, f ; test 0x20: Z = 0 because it isn't zero
W is 0x42 and Z is 0. If 0x20 had held 0, the last instruction would have set Z.
Open this example in the simulator
Watch out for
- Leaving out d makes most assemblers assume f (and warn). Write W or F explicitly so the intent is clear.