MOVLW Data Movement
Load an 8-bit constant into the W register.
| Syntax | MOVLW k |
|---|---|
| Operands | k: 8-bit literal 0-255 (0x00-0xFF) |
| Operation | k → W |
| Status bits | None |
| Words / cycles | 1 word, 1 cycle |
| Encoding | 11 00xx kkkk kkkk |
How it works
MOVLW copies the literal k into W. It is the usual first step before writing a constant to a register, because no PIC16 instruction writes a literal straight into a file register.
The literal can be written in any form the assembler understands: 0x25, 25h, b'00100101', d'37', .37 or a character such as 'A'.
Example
; MOVLW example from picsimulator.com/instructions/movlw.html
list p=16f84a
include <p16f84a.inc>
org 0
movlw 0x25 ; W = 0x25
movlw 'A' ; W = 0x41, the ASCII code for A
W ends up holding 0x41. No STATUS flags change.
Open this example in the simulator
Watch out for
- MOVLW never changes Z. To test whether W is zero after loading it, use a logic instruction such as IORLW 0 or XORLW 0.