MOVWF Data Movement

Copy the W register into a file register.

SyntaxMOVWF f
Operandsf: register address 0-127 (bank bits come from STATUS)
Operation(W) → f
Status bitsNone
Words / cycles1 word, 1 cycle
Encoding00 0000 1fff ffff

How it works

MOVWF stores W in register f. Together with MOVLW it is how a constant gets into a register: load it into W, then move W to the register.

The register is selected by the 7-bit address in the instruction plus the bank-select bits RP1:RP0 in STATUS, so writing TRISB or OPTION_REG needs bank 1 selected first.

Example

; MOVWF example from picsimulator.com/instructions/movwf.html
    list p=16f84a
    include <p16f84a.inc>

    org 0
    bsf STATUS, RP0   ; bank 1
    clrf TRISB        ; PORTB pins are outputs
    bcf STATUS, RP0   ; back to bank 0
    movlw b'10101010'
    movwf PORTB       ; RB7, RB5, RB3 and RB1 go high
    movwf 0x20        ; keep a copy in RAM

Open the LED Array widget to see every other LED on PORTB light up. RAM 0x20 also holds 0xAA.

Open this example in the simulator

Watch out for

  • Forgetting the bank: MOVWF TRISB with RP0 = 0 writes PORTB instead (both are address 0x06 within their bank).

Related instructions