SUBLW Arithmetic
Subtract W from an 8-bit constant.
| Syntax | SUBLW k |
|---|---|
| Operands | k: 8-bit literal 0-255 (0x00-0xFF) |
| Operation | k - (W) → W |
| Status bits | C DC Z |
| Words / cycles | 1 word, 1 cycle |
| Encoding | 11 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.