CPM2A_PROGRAMMING MANUAL (W353-E1-2) (986750), страница 74
Текст из файла (страница 74)
With odd or even parity, theleftmost bit of each ASCII character should be adjusted so that there is an odd oreven number of ON bits.If the parity of the ASCII code in S does not agree with the parity specified in Di,the ER Flag (SR 25503) will be turned ON and the instruction will not beexecuted.Section 7-20Conversion InstructionsFlagsER:Incorrect digit designator, or data area for destination exceeded.The source words do not contain ASCII data that can be converted tohexadecimal, i.e., values ranging from 0 to 9 or A to F.Indirectly addressed DM word is non-existent. (Content of *DM word isnot BCD, or the DM area boundary has been exceeded.)In the following example, the 2nd byte of LR 10 and the 1st byte of LR 11 are converted to hexadecimal values and those values are written to the first and second bytes of IR 200.Example00000@HEX(––)LR 10HR 10AddressInstruction0000000001LD@HEX(––)Operands00000LRHR2001010200HR 10 0 1 1 0LR 123 5 3 4LR 114 2 3 2LR 103 1 3 0Conversion tohexadecimal200 0 0 2 17-20-10 HOURS-TO-SECONDS – SEC(––)Ladder SymbolsOperand Data AreasSEC(––)@SEC(––)SSRR000000S: Beginning source word (BCD)IR, SR, AR, DM, HR, TC, LRR: Beginning result word (BCD)IR, SR, AR, DM, HR, TC, LR000: No function000LimitationsThis instruction is available in the CPM2A/CPM2C only.S and S+1 must be within the same data area.
R and R+1 must be within thesame data area. S and S+1 must be BCD and must be in the proper hours/minutes/seconds format.DM 6144 to DM 6655 cannot be used for R.DescriptionSEC(––) is used to convert time notation in hours/minutes/seconds to an equivalent in just seconds.For the source data, the seconds are designated in bits 00 through 07 and theminutes are designated in bits 08 through 15 of S. The hours are designated inS+1. The maximum is thus 9,999 hours, 59 minutes, and 59 seconds.The result is output to R and R+1. The maximum obtainable value is 35,999,999seconds.FlagsER:S and S+1 or R and R+1 are not in the same data area.423Section 7-20Conversion InstructionsS and/or S+1 do not contain BCD.Number of seconds and/or minutes exceeds 59.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 zero.When 00000 is OFF (i.e., when the execution condition is ON), the followinginstruction would convert the hours, minutes, and seconds given in HR 12 andHR 13 to seconds and store the results in DM 0100 and DM 0101 as shown.00000AddressSEC(––)HR 12DM 0100000HR 12HR 13322801752,815 hrs, 32 min,07 sDM 0100DM 01015190217310,135,927 s0000000001InstructionOperandsLD NOTSEC(––)00000HRDM1201000007-20-11 SECONDS-TO-HOURS – HMS(––)Operand Data AreasLadder SymbolsHMS(––)@HMS(––)SSRR000000S: Beginning source word (BCD)IR, SR, AR, DM, HR, TC, LRR: Beginning result word (BCD)IR, SR, AR, DM, HR, TC, LR000: No function000LimitationsThis instruction is available in the CPM2A/CPM2C only.S and S+1 must be within the same data area. R and R+1 must be within thesame data area. S and S+1 must be BCD and must be between 0 and35,999,999 seconds.DM 6144 to DM 6655 cannot be used for R.DescriptionHMS(––) is used to convert time notation in seconds to an equivalent in hours/minutes/seconds.The number of seconds designated in S and S+1 is converted to hours/minutes/seconds and placed in R and R+1.For the results, the seconds are placed in bits 00 through 07 and the minutes areplaced in bits 08 through 15 of R.
The hours are placed in R+1. The maximum is9,999 hours, 59 minutes, and 59 seconds.FlagsER:S and S+1 or R and R+1 are not in the same data area.S and/or S+1 do not contain BCD or exceed 36,000,000 seconds.Indirectly addressed DM word is non-existent. (Content of *DM word isnot BCD, or the DM area boundary has been exceeded.)EQ:424ON when the result is zero.Section 7-20Conversion InstructionsExampleWhen 00000 is OFF (i.e., when the execution condition is ON), the followinginstruction would convert the seconds given in HR 12 and HR 13 to hours, minutes, and seconds and store the results in DM 0100 and DM 0101 as shown.00000AddressHMS(––)HR 12DM 01000000000001InstructionOperandsLD NOTHMS(––)00000HRDM000HR 12HR 1351902173DM 0100DM 0101322801757-20-1210,135,927 s1201000002,815 hrs, 32 min, 07 s2’S COMPLEMENT – NEG(––)Ladder SymbolsOperand Data AreasNEG(––)@NEG(––)SSRR000000S: Source wordIR, SR, AR, DM, HR, TC, LR, #R: Result wordIR, SR, AR, DM, HR, LR000Not used.
Set to 000.LimitationsThis instruction is available in the CPM2A/CPM2C/SRM1(-V2) only.DM 6144 to DM 6655 cannot be used for R.DescriptionConverts the four-digit hexadecimal content of the source word (S) to its 2’scomplement and outputs the result to the result word (R). This operation is effectively the same as subtracting S from 0000 and outputting the result to R; it willcalculate the absolute value of negative signed binary data.If the content of S is 0000, the content of R will also be 0000 after execution andEQ (SR 25506) will be turned on.If the content of S is 8000, the content of R will also be 8000 after execution andUF (SR 25405) will be turned on.Note Refer to 2-16 Calculating with Signed Binary Data for more details.FlagsER: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 content of R is zero after execution; otherwise OFF.UF:ON when the content of S is 8000; otherwise OFF.N:ON when bit 15 of R is ON; otherwise OFF.425Section 7-20Conversion InstructionsExampleThe following example shows how to use NEG(––) to find the 2’s complement ofthe content of DM 0005 and output the result to IR 105.00100NEG(––)DM 0005105Address0000000001Instruction#000042600100DM000–OperandsLDNEG(––)#001FContent of DM 0005.#FFE1Output to IR 105.0005105000Section 7-21BCD Calculation Instructions7-21 BCD Calculation Instructions7-21-1 SET CARRY – STC(40)Ladder SymbolsSTC(40)@STC(40)When the execution condition is OFF, STC(40) is not executed. When theexecution condition is ON, STC(40) turns ON CY (SR 25504).Note Refer to Appendix B Error and Arithmetic Flag Operation for a table listing theinstructions that affect CY.7-21-2 CLEAR CARRY – CLC(41)Ladder SymbolsCLC(41)@CLC(41)When the execution condition is OFF, CLC(41) is not executed.
When theexecution condition is ON, CLC(41) turns OFF CY (SR 25504).CLEAR CARRY is used to reset (turn OFF) CY (SR 25504) to “0.”Note Refer to Appendix B Error and Arithmetic Flag Operation for a table listing theinstructions that affect CY.7-21-3 BCD ADD – ADD(30)Operand Data AreasAu: Augend word (BCD)Ladder SymbolsIR, SR, AR, DM, HR, TC, LR, #ADD(30)@ADD(30)AuAuAdAdRRAd: Addend word (BCD)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, ADD(30) is not executed. When theexecution condition is ON, ADD(30) adds the contents of Au, Ad, and CY, andplaces the result in R.
CY will be set if the result is greater than 9999.Au + Ad + CYFlagsER:CYRAu 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.)CY:ON when there is a carry in the result.EQ:ON when the result is 0.427Section 7-21BCD Calculation InstructionsIf 00002 is ON, the program represented by the following diagram clears CY withCLC(41), adds the content of IR 200 to a constant (6103), places the result in DM0100, and then moves either all zeros or 0001 into DM 0101 depending on thestatus of CY (25504). This ensures that any carry from the last digit is preservedin R+1 so that the entire result can be later handled as eight-digit data.ExampleAddressTR 000002CLC(41)ADD(30)00000000010000200003InstructionLDOUTCLC(41)ADD(30)TR200#DM#6103DM 010025504MOV(21)0000400005ANDMOV(21)#0001DM 010125504MOV(21)Operands000060000700008LDAND NOTMOV(21)#0000DM 01010000202006103010025504#DMTR00010101025504#DM00000101Although two ADD(30) can be used together to perform eight-digit BCD addition,ADDL(54) is designed specifically for this purpose.7-21-4 BCD SUBTRACT – SUB(31)Operand Data AreasMi: Minuend word (BCD)Ladder SymbolsIR, SR, AR, DM, HR, TC, LR, #SUB(31)@SUB(31)MiMiSuSuRRSu: Subtrahend word (BCD)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, SUB(31) is not executed.
When theexecution condition is ON, SUB(31) subtracts the contents of Su and CY fromMi, 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 complement to thetrue result, subtract the content of R from zero (see example below).Mi – Su – CYFlagsER:CYRMi and/or Su is not BCD.Indirectly addressed DM word is non-existent. (Content of *DM word isnot BCD, or the DM area boundary has been exceeded.)428CY:ON when the result is negative, i.e., when Mi is less than Su plus CY.EQ:ON when the result is 0.Section 7-21BCD Calculation Instructions! CautionExampleBe sure to clear the carry flag with CLC(41) before executing SUB(31) if its previous status is not required, and check the status of CY after doing a subtractionwith SUB(31).
If CY is ON as a result of executing SUB(31) (i.e., if the result isnegative), the result is output as the 10’s complement of the true answer. To convert 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 201 and places the result in HR 10.If CY is set by executing SUB(31), the result in HR 10 is subtracted from zero(note that CLC(41) is again required to obtain an accurate result), the result isplaced back in HR 10, and HR 1100 is turned ON to indicate a negative result.If CY is not set by executing SUB(31), the result is positive, the second subtraction is not performed, and HR 1100 is not turned ON.
HR 1100 is programmed asa self-maintaining bit so that a change in the status of CY will not turn it OFFwhen the program is rescanned.In this example, differentiated forms of SUB(31) are used so that the subtractionoperation is performed only once each time 00002 is turned ON. When anothersubtraction operation is to be performed, 00002 will need to be turned OFF for atleast one cycle (resetting HR 1100) and then turned back ON.TR 000002CLC(41)@SUB(31)201FirstsubtractionDM 0100HR 1025504CLC(41)@SUB(31)#0000SecondsubtractionHR 10HR 1025504HR 1100HR 1100Turned ON to indicatenegative result.429Section 7-21BCD Calculation InstructionsAddressInstruction00000000010000200003LDOUTCLC(41)@SUB(31)Operands000020TRDMHR0000400005000060000700008000090001000011ANDCLC(41)@SUB(31)LDLDORAND LDOUT#HRHRTRHRHR20101001025504000010100255041100--1100The first and second subtractions for this diagram are shown below using example data for 201 and DM 0100.Note The actual SUB(31) operation involves subtracting Su and CY from 10,000 plusMi.