PIC18CXX2
SUBWF
SUBWF
Subtract WREG from f
Subtract WREG from f (cont’d)
SUBWF
REG, 1, 0
Syntax:
[ label ]
Example 1:
SUBWF f,d,a
Before Instruction
Operands:
0 ≤ f ≤ 255
REG
=
3
2
?
d
a
[0,1]
[0,1]
WREG
C
=
=
Operation:
(f) – (WREG) → dest
After Instruction
REG
WREG
C
Z
N
=
=
=
=
=
1
2
1
0
0
Status Affected:
Encoding:
N,OV, C, DC, Z
0101
11da
ffff
ffff
; result is positive
REG, 0, 0
Description:
Subtract WREG from register 'f'
(2’s complement method). If 'd' is
SUBWF
Example 2:
0, the result is stored in WREG. If
'd' is 1, the result is stored back in
register '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).
Before Instruction
REG
=
2
2
?
WREG
C
=
=
After Instruction
REG
=
2
0
WREG
=
C
Z
N
=
=
=
1
1
0
; result is zero
REG, 1, 0
Words:
Cycles:
1
1
SUBWF
Example 3:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Before Instruction
REG
WREG
C
=
=
=
1
2
?
Decode
Read
register ’f’
Process
Data
Write to
destination
After Instruction
REG
=
FFh
;(2’s complement)
WREG
=
2
C
Z
N
=
=
=
0
0
1
; result is negative
DS39026B-page 228
Preliminary
7/99 Microchip Technology Inc.