Chapter 7 Second Development Platform VP3000
310
API Instruction code Operand Function
21 D SUB P S
1
, S
2
, D BIN subtraction
Type
Operand
Bit devices Word devices
16-bit instruction (7 steps)
SUB
Continuous
execution
type
SUBP
Pulse
execution
type
32-bit instruction (13 steps)
DSUB
ontinuous
execution
type
DSUBP
Pulse
execution
type
Associated flag:
M1020: Zero flag
M1021: Borrow flag
M1022: Carry flag
See the following descriptions.
X Y M K H KnX KnY KnM T C D
S
1
S
2
D
Caution for using operand: none
Description
S
1
: minuend
S
2
: subtrahend
D: difference
This instruction subtracts S
1
and S
2
in BIN format and stores the result in D.
The highest bit is symbolic bit 0 (+) and 1 (-), which is suitable for algebraic subtraction.
Flag changes in binary subtraction:
1. If the operation result = 0, zero flag M1020 = ON.
2. If the operation result < -32,768, borrow flag M1021 = ON.
3. If the operation result > 32,767, carry flag M1022 = ON.
Example
In 16-bit BIN subtraction:
When X0 = ON, the content in D0 minus the content in D10 and the difference is stored in D20.
X0
D0 D10
D20
SUB