!
162
00000
LD
00000
00001
CLC(41)
00002
@ADDL(54)
LR
20
DM
0010
HR
10
00003
@ADD(30)
LR
22
DM
0012
HR
12
00004
@ADB(50)
#
0000
#
0000
HR
13
@ADDL(54)
LR 20
DM 0010
HR 10
CLC(41)
00000
@ADD(30)
LR 22
DM 0012
HR 12
@ADB(50)
#0000
#0000
HR 13
Address
Instruction
Operands
5-17-7
BCD SUBTRACT – SUB(31)
Mi
: Minuend word (BCD)
IR, SR, AR, DM, HR, TC, LR, #
Su
: Subtrahend word (BCD)
IR, SR, AR, DM, HR, TC, LR, #
Ladder Symbols
Operand Data Areas
R
: Result word
IR, AR, DM, HR, LR
SUB(31)
Mi
Su
R
@SUB(31)
Mi
Su
R
When the execution condition is OFF, SUB(31) is not executed. When the
execution condition is ON, SUB(31) subtracts the contents of Su and CY
from Mi, and places the result in R. If the result is negative, CY is set and the
10’s complement of the actual result is placed in R. To convert the 10’s com-
plement to the true result, subtract the content of R from zero (see example
below).
Mi – Su – CY
CY
R
ER:
Mi and/or Su is not BCD.
Indirectly addressed DM word is non-existent. (Content of
*
DM word
is not BCD, or the DM area boundary has been exceeded.)
CY:
ON when the result is negative, i.e., when Mi is less than Su plus CY.
EQ
:
ON when the result is 0.
Caution
Be sure to clear the carry flag with CLC(41) before executing SUB(31) if its previ-
ous 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
contents of DM 0100 and CY from the content of 010 and places the result in
HR 20.
Description
Flags
Example
BCD Calculations
Section 5-17