
!
104
Caution
Be sure to clear the carry flag with CLC(44) before executing SUB(41) if its pre-
vious status is not required, and check the status of CY after doing a subtraction
with SUB(41). If CY is ON as a result of executing SUB(41) (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 0002 is ON, the following ladder program clears CY, subtracts the con-
tents of DR 0100 and CY from the content of DR 10 and places the result
back in DR 10.
If CY is set by executing SUB(41), the result in DR 10 is subtracted from zero
(note that CLC(44) is again required to obtain an accurate result), the result
is placed back in DR 10, and DR 1100 is turned ON to indicate a negative
result.
If CY is not set by executing SUB(41), the result is positive, the second sub-
traction is not performed, and DR 1100 is not turned ON. DR 1100 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 cycled again.
In this example, differentiated forms of SUB(41) are used so that the subtrac-
tion operation is performed only once each time 0002 is turned ON. When
another subtraction operation is to be performed, 0002 will need to be turned
OFF for at least one cycle (resetting DR 1100) and then turned back ON.
000
LD
0002
001
CLC(44)
002
SUB(41)
DR
10
#
0100
DR
10
003
AND
0312
004
CLC(44)
005
SUB(41)
#
0000
DR
10
DR
10
006
AND
0312
007
OUT
DR
1100
CLC(44)
SUB(41)
DR 10
#0100
DR 10
CLC(44)
SUB(41)
#0000
DR 10
DR 10
0312
DR 1100
0002
0312
First
subtraction
Second
subtraction
Turned ON to indicate
negative result.
Address
Instruction
Operands
The first and second subtractions for this diagram are shown below using
example data for DR 10.
The actual SUB(41) 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
DR 10
0089
#
– 0100
CY
– 0
Caution
Example
Note
Instruction Set
Section 3-7