120 The Essence of the PIC18® Microcontroller

advertisement
120
The Essence of the PIC18® Microcontroller
Table 5.2: Arithmetic.
Operation
Add
Mnemonic
Literal to W
W to File
W + C to File
√
addlw k
√
addwf f,d,a √
addwfc f,d,a
Clear
Set
Toggle
bcf
bsf
btg
f,n,a •
f,n,a •
f,n,a •
•
•
•
clrf
f,a
•
•
•
√
• •
√ √ √ √
√
√ √ √ √
•
•
√
• • • •
• • • •
√ √ √ √
Bit twiddle
Clear
File
Decimal Adjust
W
Decrement
File
Increment
File
Multiply
Literal with W
W with File
Negate
File
Set
File
Subtract
W from literal
W from File
F−W−B
W−F−B
#0
#00
#kk
fn
Flags
N OV Z DC C
daw
decf
f,d,a
incf
f,d,a
mullw
mulwf
k
f,a
negf
f,a
•
√
sublw k
√
subwf f,d,a
√
subwfb f,d,a
√
subfwb f,d,a
setf
Single zero bit
Zero byte
8-bit constant
Bit n of File
f,a
#1
#01
n
√ √ √ √
√ √ √ √
√ √ √ √
•
√
√
√
√
•
•
•
√
•
√
√
√
√
•
•
•
•
•
•
• •
√ √
•
√
√
√
√
•
√
√
√
√
Description
Binary addition
[W] <- [W] + #kk
[d] <- [W] + [f]
[d] <- [W] + C + [f]
Alters a single bit
[fn ] <- #0
[fn ] <- #1
[fn ] <- fn
Zeroes destination byte
[f] <- #00
Corrects addition of
packed BCD bytes
Subtract one
[f] <- [f] - #01
Add one
[f] <- [f] + #01
Unsigned 8 × 8 multiply
[PRODH:L] <- [W] x #kk
[PRODH:L] <- [W] x [f]
2’s complement sign change
[f] <- −1[f]
Sets all bits in a File to 1
[f] <- #h’FF’
Binary subtraction
[W] <- #kk - [W]
[d] <- [f] - [W]
[d] <- [f] - [W] - C
[d] <- [W] - [f] - C
Single one bit
Byte h’01’
3-bit bit specifier 0–7
addwfc
001000 d a FFFFFFFF
Like all arithmetic operations, data are processed in 8-bit chunks. In
order to facilitate multi-byte operations, instructions must be able to have
regard to the carry/borrow-out generated by a previous instruction. The
addwfc instruction is an extension to addwf but also adds the prior state
of the C flag to the outcome. For instance, addwfc h’030’,f,0:
File h’030’
XXXXXXXX
C
File h’030’
addwfc h’030’,f,0 +
YYYYYYYY
W
S=X+Y+c
NV ZDC
SSSSSSSS
Download