Delta Electronics Programmable Logic Controller DVP-PLC User Manual
Page 246
![background image](/manuals/75807/246/background.png)
6 Application Instructions API 00-49
DVP-PLC Application Manual
6-34
API Mnemonic
Operands
Function
21
D SUB P
Subtraction
Controllers
ES/EX/SS SA/SX/SC EH/SV
Bit Devices
Word Devices
Program Steps
Type
OP
X Y M S K H
KnX
KnY
KnM KnS T C D E F
S
1
* *
*
*
*
*
*
*
*
*
*
S
2
* *
*
*
*
*
*
*
*
*
*
D
*
*
*
*
*
*
*
*
SUB, SUBP: 7 steps
DSUB, DSUBP: 13 steps
PULSE 16-bit 32-bit
ES EX SS SA SX SC EH SV ES EX SS SA SX SC EH SV ES EX SS SA SX SC EH SV
Operands:
S
1
: Minuend S
2
: Subtrahend D: Remainder
Explanations:
1. If
S
1
, S
2
and D are used in device F, only 16-bit instruction is applicable.
2.
See the specifications of each model for their range of use.
3.
Flags: M1020 (zero flag); M1021 (borrow flag); M1022 (carry flag)
4.
This instruction subtracts S
1
and S
2
in BIN format and stores the result in D.
5.
The highest bit is symbolic bit 0 (+) and 1 (-), which is suitable for algebraic subtraction.
6.
Flag changes in binary subtraction
In 16-bit instruction:
a) If the operation result = 0, zero flag M1020 = On.
b) If the operation result < –32,768, borrow flag M1021 = On.
c) If the operation result > 32,767, carry flag M1022 = On.
In 32-bit instruction:
a) If the operation result = 0, zero flag M1020 = On.
b) If the operation result < –2,147,483,648, borrow flag M1021 = On.
c) If the operation result > 2,147,483,647, carry flag M1022 = On.
7.
For flag operations of SUB instruction and the positive/negative sign of the value, see the explanations in ADD
instruction on the previous page.
Program Example 1:
In 16-bit BIN subtraction:
When X0 = On, the content in D0 will minus the content in D10 and the remainder will be stored in D20.
X0
SUB
D0
D10
D20
Program Example 2:
In 32-bit BIN subtraction:
When X10 = On, the content in (D31, D30) will minus the content in (D41, D40) and the remainder will be stored in
(D51, D50). D30, D40 and D50 are low 16-bit data; D31, D41 and D51 are high 16-bit data.
X10
DSUB
D30
D40
D50
(D31, D30)
− (D41, D40) = (D51, D50)