BCD Calculations
00000
5-17-7
BCD SUBTRACT – SUB(31)
Description
Flags
!
Caution
Example
162
CLC(41)
@ADDL(54)
DM 0010
@ADD(30)
DM 0012
@ADB(50)
Ladder Symbols
SUB(31)
@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
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.
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.
Address
00000
00001
LR 20
00002
HR 10
00003
LR 22
HR 12
00004
#0000
#0000
HR 13
IR, SR, AR, DM, HR, TC, LR, #
Mi
IR, SR, AR, DM, HR, TC, LR, #
Su
R
CY
R
Section 5-17
Instruction
Operands
LD
00000
CLC(41)
@ADDL(54)
LR
DM
HR
@ADD(30)
LR
DM
HR
@ADB(50)
#
#
HR
Operand Data Areas
Mi: Minuend word (BCD)
Su: Subtrahend word (BCD)
R: Result word
IR, AR, DM, HR, LR
20
0010
10
22
0012
12
0000
0000
13
Need help?
Do you have a question about the SYSMAC C2000H and is the answer not in the manual?