ADDLW Arithmetic

Add an 8-bit constant to W.

SyntaxADDLW k
Operandsk: 8-bit literal 0-255 (0x00-0xFF)
Operation(W) + k → W
Status bitsC DC Z
Words / cycles1 word, 1 cycle
Encoding11 111x kkkk kkkk

How it works

ADDLW adds the literal k to W and leaves the low 8 bits of the sum in W. Like ADDWF, it sets C on a carry out of bit 7, DC on a carry out of bit 3 and Z when the result is 0.

A common use is turning a digit 0-9 into its ASCII character by adding 0x30 ('0').

Example

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

    org 0
    movlw 0xF0
    addlw 0x20        ; 0xF0 + 0x20 = 0x110: W = 0x10, C = 1

The sum overflows 8 bits, so W keeps 0x10 and C is set.

Open this example in the simulator

Watch out for

  • There is no subtract-literal-from-W instruction. To compute W - k, use ADDLW with the two's complement of k (for example ADDLW -5); SUBLW computes k - W instead.

Related instructions