ANDWF Logic

Bitwise AND of W and a file register.

SyntaxANDWF f, d
Operandsf: 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) AND (f) → destination
Status bitsZ
Words / cycles1 word, 1 cycle
Encoding00 0101 dfff ffff

How it works

ANDWF ANDs W with register f bit by bit. A bit in the result is 1 only where both inputs have a 1, so W acts as a mask that keeps the bits you choose. Z is set if the result is 0.

Example

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

    org 0
    movlw 0x3C
    movwf 0x20
    movlw 0x0F        ; mask: keep the low nibble
    andwf 0x20, w     ; W = 0x3C AND 0x0F = 0x0C

W holds 0x0C; the register still holds 0x3C because the result went to W.

Open this example in the simulator

Related instructions