103
4
4 Instructions 4.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 ADD instruction requires contact driving and has three operands. Use this instruction to algebraically
add the values in S1 and S2 together 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 ADD 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.
M8
ǒADD D100 D110 D120Ǔ
When M8 is set, the sum of D100
(augend) and D110 (addend) is
stored in D120. D120 = 8 + (–12) =
k-4 if D100 = K8 and D110 = K-12.
M8
ǒADDP D100 D110 D100Ǔ
When M8 is set, the sum of D100
(augend) and D110 (addend) is
stored in D100.
Example 1: Example 2:
SUB: Binary number subtraction
◆
Overview
The SUB instruction subtracts one binary number from another.
SUB S1 S2 D
Binary number
subtraction
Applicable model:
H3U
S1 Subtrahend
Data, or address of the word element that stores the
data
16-bit instruction
(7 steps)
SUB: Continuous
execution
SUBP: Pulse
execution
32-bit instruction
(13 steps)
DSUB: Continuous
execution
DSUBP: Pulse
execution
S2 Minuend
Data, or address of the word element that stores the
data
D Difference Address of the word element that stores the data