!
7-21
Section
BCD Calculation Instructions
459
Caution
Be sure to clear the carry flag with CLC(41) before executing SUB(31) if its pre-
vious status is not required, and check the status of CY after doing a subtraction
with SUB(31). If CY is ON as a result of executing SUB(31) (i.e., if the result is
negative), the result is output as the 10’s complement of the true answer. To con-
vert the output result to the true value, subtract the value in R from 0.
When 00002 is ON, the following ladder program clears CY, subtracts the con-
tents of DM 0100 and CY from the content of 201 and places the result in HR 10.
If CY is set by executing SUB(31), the result in HR 10 is subtracted from zero
(note that CLC(41) is again required to obtain an accurate result), the result is
placed back in HR 10, and HR 1100 is turned ON to indicate a negative result.
If CY is not set by executing SUB(31), the result is positive, the second subtrac-
tion is not performed, and HR 1100 is not turned ON. HR 1100 is programmed as
a self-maintaining bit so that a change in the status of CY will not turn it OFF
when the program is rescanned.
In this example, differentiated forms of SUB(31) are used so that the subtraction
operation is performed only once each time 00002 is turned ON. When another
subtraction operation is to be performed, 00002 will need to be turned OFF for at
least one cycle (resetting HR 1100) and then turned back ON.
CLC(41)
@SUB(31)
201
DM 0100
HR 10
CLC(41)
@SUB(31)
#0000
HR 10
HR 10
TR 0
25504
HR 1100
00002
25504
HR 1100
First
subtraction
Second
subtraction
Turned ON to indicate
negative result.
Example