ADDWF Arithmetic

Add W to a file register and keep the sum in W or the register.

SyntaxADDWF 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) + (f) → destination
Status bitsC DC Z
Words / cycles1 word, 1 cycle
Encoding00 0111 dfff ffff

How it works

ADDWF adds W and register f as 8-bit unsigned values. The low 8 bits of the sum go to the destination.

C is set when the sum is larger than 255 (a carry out of bit 7), DC when the low nibbles carry out of bit 3, and Z when the 8-bit result is 0.

ADDWF PCL, F is also how computed jumps and RETLW tables work: adding W to the program counter jumps W instructions forward.

Example

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

    org 0
    movlw 0x0F
    movwf 0x20        ; 0x20 = 0x0F
    movlw 0x01        ; W = 0x01
    addwf 0x20, f     ; 0x20 = 0x10; DC = 1 (low nibble carried), C = 0

0x0F + 0x01 = 0x10, so the low nibble carries into bit 4 and DC is set. The sum is below 256, so C stays 0.

Open this example in the simulator

Watch out for

  • Adding to PCL in a table more than 256 words into program memory needs PCLATH set first, and the table must not cross a 256-word boundary.

Related instructions