240
Note Be sure to clear the carry flag with CLC(079) before executing SUB(071) if its
previous status is not required, and check the status of CY after doing a subtrac-
tion with SUB(071). If CY is ON as a result of executing SUB(071) (i.e., if the re-
sult is negative), the result is output as the 10’s complement of the true answer.
To convert the output result to the true value, subtract the value in R from 0.
When CIO 000002 is ON in the following example, the following ladder program
clears CY, subtracts the contents of D00100 and CY from the content of
CIO 0010, and places the result in CIO 0200.
If CY is set by executing SUB(071), the result in CIO 0200 is subtracted from
zero (note that CLC(079) is again required to obtain an accurate result), the re-
sult is placed back in CIO 0200, and CIO 002100 is turned ON to indicate a neg-
ative result.
If CY is not set by executing SUB(071), the result is positive, the second subtrac-
tion is not performed, and CIO 002100 is not turned ON. CIO 002100 is pro-
grammed as a self-maintaining bit so that a change in the status of CY will not
turn it OFF when the program is re-scanned.
In this example, differentiated forms of SUB(071) are used so that the subtrac-
tion operation is performed only once each time CIO 000002 turns ON. When
another subtraction operation is to be performed, CIO 000002 will need to be
turned OFF for at least one scan (resetting CIO 002100) and then turned back
ON.
(079)
CLC
(071)
SUB
0010
D00100
0200
0000
02
A500
04(CY)
TR0
(079)
CLC
(071)
SUB
#0000
0200
0200
0021
00
A500
04(CY)
0021
00
00000
LD
000002
00001
OUT
TR0
00002
CLC(079)
00003
SUB(071)
0010
D00100
0200
00004
AND
A50004
00005
CLC(079)
00006
SUB(071)
#0000
0200
0200
00007
LD
TR0
00008
AND
A50004
00009
OR
002100
00010
OUT
002100
Address Instruction
Operands
First
subtraction
Second
subtraction
Turned ON to
indicate nega-
tive result.
The first and second subtractions for this diagram are shown below using exam-
ple data for CIO 0010 and D00100.
The actual SUB(071) operation involves subtracting Su and CY from 10,000
plus Mi. For positive results the leftmost digit is truncated. For negative re-
sults the 10s complement is obtained. The procedure for establishing the cor-
rect answer is given below.
First Subtraction
CIO 0010
1029
D00100
– 3452
CY
–
0
CIO 0200
7577
(1029 + (10000 – 3452))
CY
1 (negative
result)
Example
Note
BCD Calculation Instructions
Section 5-18
Summary of Contents for CVM1D
Page 462: ...SYSMAC CVM1D Duplex System Programmable Controllers Operation Manual Revised August 2001...
Page 463: ...iv...
Page 465: ...vi...