11: BINARY ARITHMETIC INSTRUCTIONS
11-2 USER’S MANUAL
Using Carry or Borrow Signals
When the D1 (destination) data exceeds 65535 as a result of addition, a carry occurs, and special internal relay M303 is
turned on. When the D1 (destination) data is less than zero as a result of subtraction, a borrow occurs, and special internal
relay M303 is turned on.
There are three ways to program the carrying process (see examples below). If a carry never goes on, the program does not
have to include internal relay M303 to process carrying. If a carry goes on unexpectedly, an output can be programmed to
be set as a warning indicator. If a carry goes on, the number of times a carry occurs can be added to be used as one word
data in a specified register.
Example: ADD
This example demonstrates the use of a carry signal from special internal relay M303 to set an alarm signal.
Example: Repeat Operation Using ADD
This example uses the repeat operation to total the current values of four counters using the ADD (addition) instruction.
Example: SUB
The following example demonstrates the use of special internal relay M303 to process a borrow.
Example: MUL
Example: DIV
I0
ADD REP
**
S1
D2
S2
500
D1
D2
SOTU
Q0
SET
M303
I1
Q0
RST
D2 + 500 → D2
When a carry occurs, output Q0 is set as a warning indicator.
When the acknowledge pushbutton (input I1) is pressed,
the warning indicator is reset.
Acknowledge
Pushbutton
I0
ADD S1 R
C0
S2
D0
D1
D0
SOTU
When input I0 is turned on, the MOV (move) instruction
sets 0 to data register D0.
If the current values of counters C0 through C3 are 10, 20,
30, and 40, respectively, then the ADD instruction with 4
repeat cycles totalizes the current values as follows:
C0 (10) + D0 (0) → D0 (10)
C1 (20) + D0 (10) → D0 (30)
C2 (30) + D0 (30) → D0 (60)
C3 (40) + D0 (60) → D0 (100)
Data register D0 stores the final result of 100.
MOV S1
0
D1
D0
REP
**
REP
4
I0
SUB REP
**
S1
D12
S2
7000
D1
D12
SOTU
M303
D12 – 7000 → D12
To process borrowing so that the number of
times a borrow occurs is subtracted from D13.
When a borrow occurs, D13 is decremented by one.
SUB REP
**
S1
D13
S2
1
D1
D13
I1
MUL REP
**
S1
D10
S2
D20
D1
D30
D10 × D20 → D30
When input I1 is on, data of D10 is multiplied by data of D20,
and the result is set to D30.
Note: When the result exceeds 65535, a user program execution error will result, turning on error indicator ERR1 and spe-
cial internal relay M304 (user program execution error). The result is not set to the destination operand.
I2
DIV REP
**
S1
D10
S2
D20
D1
D30
D10 ÷ D20 → D30 (quotient), D31 (remainder)
When input I2 is on, data of D10 is divided by data of D20. The
quotient is set to D30, and the remainder is set to D31.
Note: Destination uses two word operands, so do not use data register D99 as destination operand D1, otherwise a user
program syntax error occurs, and error indicator ERR1 is lit. When using a bit operand such as internal relay for destina-
tion, 32 internal relays are required; so do not use internal relay M251 or a larger number as destination operand D1.