SUBLW Arithmetic

Subtract W from an 8-bit constant.

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

How it works

SUBLW computes the literal minus W (not W minus the literal) and puts the result in W. As with SUBWF, C = 1 means no borrow (k ≥ W) and Z = 1 means the two were equal.

Example

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

    org 0
    movlw 0x03
    sublw 0x05        ; W = 5 - 3 = 2, C = 1

W is 2 and C is set because 5 is at least 3.

Open this example in the simulator

Watch out for

  • To subtract a constant from W, use ADDLW with the negative value (ADDLW -3), not SUBLW.

Related instructions