CPM2A_PROGRAMMING MANUAL (W353-E1-2) (986750), страница 75
Текст из файла (страница 75)
For positive results the leftmost digit is truncated. For negative results the10s complement is obtained. The procedure for establishing the correct answeris given below.First SubtractionIR 2011029DM 0100 – 3452CY–0HR 107577 (1029 + (10000 – 3452))CY1(negative result)Second Subtraction0000HR 10 –7577CY–0HR 10 2423 (0000 + (10000 – 7577))CY1(negative result)In the above case, the program would turn ON HR 1100 to indicate that the valueheld in HR 10 is negative.7-21-5 BCD MULTIPLY – MUL(32)Operand Data AreasMd: Multiplicand (BCD)Ladder SymbolsIR, SR, AR, DM, HR, TC, LR, #MUL(32)@MUL(32)MdMdMrMrRRMr: Multiplier (BCD)Limitations430DM 6144 to DM 6655 cannot be used for R.IR, SR, AR, DM, HR, TC, LR, #R: First result wordIR, SR, AR, DM, HR LRSection 7-21BCD Calculation InstructionsDescriptionWhen the execution condition is OFF, MUL(32) is not executed. When theexecution condition is ON, MUL(32) multiplies Md by the content of Mr, andplaces the result In R and R+1.MdXR +1ExampleMrRWhen IR 00000 is ON with the following program, the contents of IR 013 andDM 0005 are multiplied and the result is placed in HR 07 and HR 08.
Exampledata and calculations are shown below the program.00000AddressMUL(32)0000000001013DM 00050FlagsER:00000DMHR3Md: IR 0133560Mr: DM 00050253R: HR 0790R+1: HR 08008OperandsLDMUL(32)HR 07XInstruction0130005070Md and/or Mr is not BCD.Indirectly addressed DM word is non-existent. (Content of *DM word isnot BCD, or the DM area boundary has been exceeded.)CY:ON when there is a carry in the result.EQ:ON when the result is 0.7-21-6 BCD DIVIDE – DIV(33)Operand Data AreasLadder SymbolDd: Dividend word (BCD)IR, SR, AR, DM, HR, TC, LR, #DIV(33)Dr: Divisor word (BCD)DdDrRLimitationsIR, SR, AR, DM, HR, TC, LR, #R: First result word (BCD)IR, SR, AR, DM, HR, LRR and R+1 must be in the same data area. DM 6144 to DM 6655 cannot be usedfor R.431Section 7-21BCD Calculation InstructionsDescriptionWhen the execution condition is OFF, DIV(33) is not executed and the programmoves to the next instruction.
When the execution condition is ON, Dd is dividedby Dr and the result is placed in R and R + 1: the quotient in R and the remainderin R + 1.RemainderQuotientR+1RDrFlagsER:DdDd or Dr is not in BCD.Indirectly addressed DM word is non-existent. (Content of *DM word isnot BCD, or the DM area boundary has been exceeded.)EQ:ExampleON when the result is 0.When IR 00000 is ON with the following program, the content of IR 216 is dividedby the content of HR 09 and the result is placed in DM 0017 and DM 0018. Example data and calculations are shown below the program.00000AddressDIV(33)2160000000001InstructionOperandsLDDIV(33)00000HR 09DM 0017Quotient10R: DM 0017150Dd: HR 090033RemainderHRDM216090017R + 1: DM 00180002Dd: IR 2164527-21-7 DOUBLE BCD ADD – ADDL(54)Operand Data AreasAu: First augend word (BCD)Ladder SymbolsIR, SR, AR, DM, HR, TC, LRADDL(54)@ADDL(54)AuAuAdAdRRAd: First addend word (BCD)Limitations432DM 6144 to DM 6655 cannot be used for R.IR, SR, AR, DM, HR, TC, LRR: First result wordIR, SR, AR, DM, HR, LRSection 7-21BCD Calculation InstructionsDescriptionWhen the execution condition is OFF, ADDL(54) is not executed.
When theexecution condition is ON, ADDL(54) adds the contents of CY to the 8-digit value in Au and Au+1 to the 8-digit value in Ad and Ad+1, and places the result in Rand R+1. CY will be set if the result is greater than 99999999.Au + 1AuAd + 1Ad+CYFlagsER:CYR+1RAu and/or Ad is not BCD.Indirectly addressed DM word is non-existent. (Content of *DM word isnot BCD, or the DM area boundary has been exceeded.)ExampleCY:ON when there is a carry in the result.EQ:ON when the result is 0.When 00000 is ON, the following program section adds two 12-digit numbers,the first contained in LR 00 through LR 02 and the second in DM 0010 throughDM 0012.
The result is placed in HR 10 through HR 13.The rightmost 8 digits of the two numbers are added using ADDL(54), i.e., thecontents of LR 00 and LR 01 are added to DM 0010 and DM 0011 and the resultsis placed in HR 10 and HR 11. The second addition adds the leftmost 4 digits ofeach number using ADD(30), and includes any carry from the first addition.
Thelast instruction, ADB(50) (see 7-22-1 BINARY ADD – ADB(50)) adds two allzero constants to place any carry from the second addition into HR 13.00000AddressInstruction000000000100002LDCLC(41)@ADDL(54)OperandsCLC(41)@ADDL(54)LR 00DM 0010HR 10@ADD(30)00003DM 0012HR 12#0000#0000HR 1300004LRDMHR00001010LRDMHR02001212##HR0000000013@ADD(30)LR 02@ADB(50)00000@ADB(50)433Section 7-21BCD Calculation Instructions7-21-8 DOUBLE BCD SUBTRACT – SUBL(55)Operand Data AreasMi: First minuend word (BCD)Ladder SymbolsIR, SR, AR, DM, HR, TC, LR, #SUBL(55)@SUBL(55)MiMiSuSuRRSu: First subtrahend word (BCD)IR, SR, AR, DM, HR, TC, LR, #R: First result wordIR, SR, AR, DM, HR, LRLimitationsDM 6144 to DM 6655 cannot be used for R.DescriptionWhen the execution condition is OFF, SUBL(55) is not executed.
When theexecution condition is ON, SUBL(55) subtracts CY and the 8-digit contents of Suand Su+1 from the 8-digit value in Mi and Mi+1, and places the result in R andR+1. If the result is negative, CY is set and the 10’s complement of the actualresult is placed in R. To convert the 10’s complement to the true result, subtractthe content of R from zero. Since an 8-digit constant cannot be directly entered,use the BSET(71) instruction (see 7-17-4 BLOCK SET – BSET(71)) to create an8-digit constant.Mi + 1MiSu + 1Su–CYFlagsER:CYR+1RMi, M+1,Su, or Su+1 are not BCD.Indirectly addressed DM word is non-existent.
(Content of *DM word isnot BCD, or the DM area boundary has been exceeded.)434CY:ON when the result is negative, i.e., when Mi is less than Su.EQ:ON when the result is 0.Section 7-21BCD Calculation InstructionsExampleThe following example works much like that for single-word subtraction. In thisexample, however, BSET(71) is required to clear the content of DM 0000 andDM 0001 so that a negative result can be subtracted from 0 (inputting an 8-digitconstant is not possible).TR 000003CLC(41)Firstsubtraction@SUBL(55)HR 00220DM 010025504@BSET(71)#0000DM 0000DM 0001CLC(41)Secondsubtraction@SUBL(55)DM 0000DM 0100DM 010025504HR 0100HR 0100Address00000000010000200003Turned ON to indicatenegative result.InstructionLDOUTCLC(41)@SUBL(55)OperandsTRHRDM0000400005AND@BSET(71)#DMDM00003000220010025504000000000001Address00006000070000800009000100001100012InstructionOperandsCLC(41)@SUBL(55)LDLDORAND LDOUTDMDMDMTRHR0000010001000255040100HR0100435Section 7-21BCD Calculation Instructions7-21-9 DOUBLE BCD MULTIPLY – MULL(56)Operand Data AreasMd: First multiplicand word (BCD)Ladder SymbolsIR, SR, AR, DM, HR, TC, LRMULL(56)@MULL(56)MdMdMrMrRRMr: First multiplier word (BCD)IR, SR, AR, DM, HR, TC, LRR: First result wordIR, SR, AR, DM, HR LRLimitationsDM 6144 to DM 6655 cannot be used for R.DescriptionWhen the execution condition is OFF, MULL(56) is not executed.
When theexecution condition is ON, MULL(56) multiplies the eight-digit content of Md andMd+1 by the content of Mr and Mr+1, and places the result in R to R+3.xR+3FlagsER:R+2Md + 1MdMr + 1MrR+1RMd, Md+1,Mr, or Mr+1 is not BCD.Indirectly addressed DM word is non-existent. (Content of *DM word isnot BCD, or the DM area boundary has been exceeded.)ON when there is a carry in the result.ON when the result is 0.CY:EQ:7-21-10 DOUBLE BCD DIVIDE – DIVL(57)Operand Data AreasDd: First dividend word (BCD)Ladder SymbolsIR, SR, AR, DM, HR, TC, LRDIVL(57)@DIVL(57)DdDdDrDrRRDr: First divisor word (BCD)IR, SR, AR, DM, HR, TC, LRR: First result wordIR, SR, AR, DM, HR LRLimitationsDM 6144 to DM 6655 cannot be used for R.DescriptionWhen the execution condition is OFF, DIVL(57) is not executed.
When theexecution condition is ON, DIVL(57) the eight-digit content of Dd and D+1 is divided by the content of Dr and Dr+1 and the result is placed in R to R+3: the quotient in R and R+1, the remainder in R+2 and R+3.RemainderR+3Dr+1436R+2DrQuotientR+1RDd+1DdSection 7-22Binary Calculation InstructionsFlagsER:Dr and Dr+1 contain 0.Dd, Dd+1, Dr, or Dr+1 is not BCD.Indirectly addressed DM word is non-existent.
(Content of *DM word isnot BCD, or the DM area boundary has been exceeded.)EQ:ON when the result is 0.7-22 Binary Calculation Instructions7-22-1 BINARY ADD – ADB(50)Operand Data AreasAu: Augend word (binary)Ladder SymbolsIR, SR, AR, DM, HR, TC, LR, #ADB(50)@ADB(50)AuAuAdAdRRAd: Addend word (binary)IR, SR, AR, DM, HR, TC, LR, #R: Result wordIR, SR, AR, DM, HR, LRLimitationsDM 6144 to DM 6655 cannot be used for R.DescriptionWhen the execution condition is OFF, ADB(50) is not executed. When theexecution condition is ON, ADB(50) adds the contents of Au, Ad, and CY, andplaces the result in R.
CY will be set if the result is greater than FFFF.Au + Ad + CYCYRADB(50) can also be used to add signed binary data. With the CPM1A, CPM2A,CPM2C, and SRM1(-V2), the underflow and overflow flags (SR 25404 andSR 25405) indicate whether the result has exceeded the lower or upper limits ofthe 16-bit signed binary data range.FlagsER:Indirectly addressed DM word is non-existent.
(Content of *DM word isnot BCD, or the DM area boundary has been exceeded.)CY:ON when the result is greater than FFFF.EQ:ON when the result is 0.OF:ON when the result exceeds +32,767 (7FFF).UF:ON when the result is below –32,768 (8000).437Section 7-22Binary Calculation InstructionsExampleThe following example shows a four-digit addition with CY used to place either#0000 or #0001 into R+1 to ensure that any carry is preserved.AddressTR 00000000000000010000200003CLC(41)ADB(50)InstructionLDOUTCLC(41)ADB(50)Operands200DM 0100HR 10DMHR=R255040000400005MOV(21)#0000HR 11AND NOTMOV(21)= R+125504MOV(21)#0001HR 11= R+1000060000700008LDANDMOV(21)000000TR20001001025504#HRTR000011025504#HR0000111In the case below, A6E2 + 80C5 = 127A7.
The result is a 5-digit number, so CY(SR 25504) = 1, and the content of R + 1 becomes #0001.+0R+1: HR 11001AAu: IR 2006E28Ad: DM 01000C52R: HR 107A7Note For signed binary calculations, the status of the UF and OF flags indicate whether the result has exceeded the signed binary data range (–32,768 (8000) to+32,767 (7FFF)).7-22-2 BINARY SUBTRACT – SBB(51)Operand Data AreasMi: Minuend word (binary)Ladder SymbolsIR, SR, AR, DM, HR, TC, LR, #SBB(51)@SBB(51)MiMiSuSuRRSu: Subtrahend word (binary)Limitations438DM 6144 to DM 6655 cannot be used for R.IR, SR, AR, DM, HR, TC, LR, #R: Result wordIR, SR, AR, DM, HR, LRSection 7-22Binary Calculation InstructionsDescriptionWhen the execution condition is OFF, SBB(51) is not executed.
When theexecution condition is ON, SBB(51) subtracts the contents of Su and CY from Miand places the result in R. If the result is negative, CY is set and the 2’s complement of the actual result is placed in R.Mi – Su – CYCYRSBB(51) can also be used to subtract signed binary data. With the CPM1A,CPM2A, CPM2C, and SRM1(-V2), the underflow and overflow flags (SR 25404and SR 25405) indicate whether the result has exceeded the lower or upper limits of the 16-bit signed binary data range.FlagsExampleER:Indirectly addressed DM word is non-existent.
(Content of *DM word isnot 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.OF:ON when the result exceeds +32,767 (7FFF).UF:ON when the result is below –32,768 (8000).The following example shows a four-digit subtraction. When IR 00001 is ON, thecontent of LR 00 and CY are subtracted from the content of IR 002 and the resultis written to HR 01.CY is turned ON if the result is negative.