104
4
4 Instructions4.4.1 Four Arithmetic Operations
◆
Operands
Operand
Bit Element Word Element
System·User System·User Bit Designation Indexed Address Constant
Real
Number
S1 X Y M T C S SM D R T C SD KnX KnY KnM KnS KnSM
V,Z
Modication K H E
S2 X Y M T C S SM D R T C SD KnX KnY KnM KnS KnSM
V,Z
Modication K H E
D X Y M T C S SM D R T C SD KnX KnY KnM KnS KnSM
V,Z
Modication K H E
Note: The elements in gray background are supported.
◆
Function
The SUB instruction requires contact driving and has three operands. Use this instruction to algebraically
subtract the value in S2 from that in S1 in BIN mode. The result is stored in D. The variables in the
algebraic operation are processed as signed numbers. The highest bit is the sign bit. The value 0 indicates
a positive number, whereas the value 1 indicates a negative number.
The zero ag M8020 is set if the result of the calculation is 0.
The carry ag M8022 is set if the result of the calculation is greater than 32,767 (for a 16-bit operation) or
–2,147,483,647 (for a 32-bit operation).
The borrow ag M8021 is set if the result of the calculation is less than –32,768 (for a 16-bit operation) or
–2,147,483,648 (for a 32-bit operation).
In 32-bit operation, the variable addresses in the SUB instruction contain the lower 16 bits, and the adjacent
high-numbered address unit contains the higher 16 bits. Avoid repeated or overlapping addresses during
programming.
Example:
M8
ǒSUB D100 D110 D120Ǔ
When M8 is set, the difference
between D100 (subtrahend) and
D110 (minuend) is stored in D120.
D120 = 10 – 8 = K2 if D100 = K10
and D110 = K8.