
PIC18F2480/2580/4480/4580
DS39637A-page 398
Preliminary
2004 Microchip Technology Inc.
SUBWFB
Example 1:
Before Instruction
REG
W
C
After Instruction
REG
W
C
Z
N
Example 2:
Before Instruction
REG
W
C
After Instruction
REG
W
C
Z
N
Example 3:
Before Instruction
REG
W
C
After Instruction
REG
SWAPF
Example:
Subtract W from f with Borrow
Syntax:
Operands:
SUBWFB f {,d {,a}}
0
≤
f
≤
255
d
∈
[0,1]
a
∈
[0,1]
(f) – (W) – (C)
→
dest
N, OV, C, DC, Z
Operation:
Status Affected:
Encoding:
Description:
0101
Subtract W and the Carry flag (borrow)
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 register ‘f’ (default).
If ‘a(chǎn)’ is ‘
0
’, the Access Bank is selected.
If ‘a(chǎn)’ is ‘
1
’, the BSR is used to select the
GPR bank (default).
If ‘a(chǎn)’ is ‘
0
’ and the extended instruction
set is enabled, this instruction operates
in Indexed Literal Offset Addressing
mode whenever f
≤
95 (5Fh). See
Section 25.2.3 “Byte-Oriented and
Bit-Oriented Instructions in Indexed
Literal Offset Mode”
for details.
1
1
10da
ffff
ffff
Words:
Cycles:
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register ‘f’
Process
Data
Write to
destination
SUBWFB REG, 1, 0
=
=
=
19h
0Dh
1
(0001 1001)
(0000 1101)
=
=
=
=
=
0Ch
0Dh
1
0
0
(0000 1011)
(0000 1101)
; result is positive
REG, 0, 0
SUBWFB
=
=
=
1Bh
1Ah
0
(0001 1011)
(0001 1010)
=
=
=
=
=
1Bh
00h
1
1
0
(0001 1011)
; result is zero
SUBWFB REG, 1, 0
=
=
=
03h
0Eh
1
(0000 0011)
(0000 1101)
=
F5h
(1111 0100)
; [2’s comp]
(0000 1101)
W
C
Z
N
=
=
=
=
0Eh
0
0
1
; result is negative
Swap f
Syntax:
SWAPF f {,d {,a}}
Operands:
0
≤
f
≤
255
d
∈
[0,1]
a
∈
[0,1]
(f<3:0>)
→
dest<7:4>,
(f<7:4>)
→
dest<3:0>
Operation:
Status Affected:
None
Encoding:
0011
10da
ffff
ffff
Description:
The upper and lower nibbles of register
‘f’ are exchanged. If ‘d’ is ‘
0
’, the result
is placed in W. If ‘d’ is ‘
1
’, the result is
placed in register ‘f’ (default).
If ‘a(chǎn)’ is ‘
0
’, the Access Bank is selected.
If ‘a(chǎn)’ is ‘
1
’, the BSR is used to select the
GPR bank (default).
If ‘a(chǎn)’ is ‘
0
’ and the extended instruction
set is enabled, this instruction operates
in Indexed Literal Offset Addressing
mode whenever f
≤
95 (5Fh). See
Section 25.2.3 “Byte-Oriented and
Bit-Oriented Instructions in Indexed
Literal Offset Mode”
for details.
Words:
1
Cycles:
1
Q Cycle Activity:
Q1
Q2
Q3
Q4
Decode
Read
register ‘f’
Process
Data
Write to
destination
SWAPF
REG, 1, 0
Before Instruction
REG
After Instruction
REG
=
53h
=
35h