PIC18FXX20
SUBLW
Subtract W from literal
SUBWF
Syntax:
Subtract W from f
Syntax:
[ label ] SUBLW k
0 ≤ k ≤ 255
k – (W) → W
[ label ] SUBWF f [,d [,a]
Operands:
Operation:
Status Affected:
Encoding:
Operands:
0 ≤ f ≤ 255
d ∈ [0,1]
a ∈ [0,1]
(f) – (W) → dest
N, OV, C, DC, Z
N, OV, C, DC, Z
Operation:
Status Affected:
Encoding:
0000
1000
kkkk
kkkk
Description:
W is subtracted from the eight-bit
literal 'k'. The result is placed in
W.
1
1
0101
11da
ffff
ffff
Description:
Subtract W from register 'f' (2’s
complement method). If 'd' is 0,
the result is stored in W. If 'd' is 1,
the result is stored back in regis-
ter 'f' (default). If ‘a’ is 0, the
Access Bank will be selected,
overriding the BSR value. If ‘a’ is
1, then the bank will be selected
as per the BSR value (default).
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
Process
Write to W
literal 'k'
Data
SUBLW 0x02
Example 1:
Words:
Cycles:
1
1
Before Instruction
W
=
1
?
Q Cycle Activity:
Q1
C
=
Q2
Q3
Process
Data
Q4
After Instruction
Decode
Read
Write to
W
=
1
register 'f'
destination
C
Z
=
=
=
1
0
0
; result is positive
SUBWF
REG, 1, 0
Example 1:
N
SUBLW 0x02
Example 2:
Before Instruction
REG
=
3
Before Instruction
W
=
2
W
=
2
?
C
=
?
C
=
After Instruction
After Instruction
REG
W
=
=
1
2
W
=
0
C
Z
=
=
=
1
0
0
; result is positive
C
Z
=
=
=
1
1
0
; result is zero
N
N
SUBWF
REG, 0, 0
Example 2:
SUBLW 0x02
Example 3:
Before Instruction
Before Instruction
REG
=
2
W
=
3
?
W
=
2
C
=
C
=
?
After Instruction
After Instruction
W
=
FF ; (2’s complement)
REG
W
=
=
2
0
C
Z
=
=
=
0
0
1
; result is negative
C
Z
=
=
=
1
1
0
; result is zero
N
N
SUBWF
REG, 1, 0
Example 3:
Before Instruction
REG
=
1
W
=
2
C
=
?
After Instruction
REG
W
=
=
FFh ;(2’s complement)
2
C
Z
=
=
=
0
0
1
; result is negative
N
2003 Microchip Technology Inc.
Advance Information
DS39609A-page 295