BCD Calculation Instructions
Example
TR 0
00002
25504
25504
7-21-4 BCD SUBTRACT – SUB(31)
Limitations
Description
Flags
458
If 00002 is ON, the program represented by the following diagram clears CY with
CLC(41), adds the content of IR 200 to a constant (6103), places the result in DM
0100, and then moves either all zeros or 0001 into DM 0101 depending on the
status of CY (25504). This ensures that any carry from the last digit is preserved
in R+1 so that the entire result can be later handled as eight-digit data.
Although two ADD(30) can be used together to perform eight-digit BCD addition,
ADDL(54) is designed specifically for this purpose.
Ladder Symbols
SUB(31)
@SUB(31)
Mi
Su
R
DM 6144 to DM 6655 cannot be used for 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 com-
plement of the actual result is placed in R. To convert the 10's complement 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.
Address Instruction
00000
LD
CLC(41)
00001
OUT
00002
CLC(41)
00003
ADD(30)
ADD(30)
200
#6103
DM 0100
00004
AND
00005
MOV(21)
MOV(21)
#0001
DM 0101
00006
LD
00007
AND NOT
MOV(21)
00008
MOV(21)
#0000
DM 0101
IR, SR, AR, DM, HR, TC, LR, #
Su: Subtrahend word (BCD)
Mi
IR, SR, AR, DM, HR, TC, LR, #
Su
R
CY
Section
7-21
Operands
00002
TR
0
200
#
6103
DM
0100
25504
#
0001
DM
0101
TR
0
25504
#
0000
DM
0101
Operand Data Areas
Mi: Minuend word (BCD)
R: Result word
IR, SR, AR, DM, HR, LR
R
Need help?
Do you have a question about the CPM1 - PROGRAMING MANUAL 02-2001 and is the answer not in the manual?