CPM2A_PROGRAMMING MANUAL (W353-E1-2) (986750), страница 77
Текст из файла (страница 77)
When the execution condition is ON, MIN(––) searches the range of memory from R1 to R1+N–1for the address that contains the minimum value and outputs the minimum valueto the destination word (D).The address is identified differently for the DM area:1, 2, 3...4441. For an address in the DM area, the word address is written to C+1. For example, if the address containing the minimum value is DM 0114, then #0114is written in D+1.Section 7-23Special Math Instructions2.
For an address in another data area, the number of addresses from the beginning of the search is written to D+1. For example, if the address containing the minimum value is IR 114 and the first word in the search range isIR 014, then #0100 is written in D+1.If bit 14 of C is ON and more than one address contains the same minimum value, the position of the lowest of the addresses will be output to D+1. The positionwill be output as the DM address for the DM area, but as an absolute positionrelative to the first word in the range for all other areas.The number of words within the range (N) is contained in the 3 rightmost digits ofC, which must be BCD between 001 and 999.When bit 15 of C is OFF, data within the range is treated as unsigned binary andwhen it is ON the data is treated as signed binary.151413121100C:Number of wordsin range (N: 001 to 999 BCD)Not used – set to zero.Not used – set to zero.! CautionFlagsOutput address to D+1?1 (ON): Yes.0 (OFF): No.If bit 14 of C is ON, values above #8000 are treated as negative numbers, so theresults will differ depending on the specified data type.
Be sure that the correctdata type is specified.ER:Indirectly addressed DM word is non-existent. (Content of *DM word isnot BCD, or the DM area boundary has been exceeded.)R1 and R1+N–1 are not in the same data area.EQ:ExampleON when the minimum value is #0000.When IR 00000 is ON, the control data in DM 0300 (4010) will cause a search forthe maximum value in the 10 words starting at DM 0000. The smallest unsigned445Section 7-23Special Math Instructionsvalue will be stored in DM 0500. The address of the word containing the minimum value (0014) will be stored in DM 0501.00000MIN(––)DM 0300DM 0000Address0000000001Instruction00000DMDMDMDM 0500DM 030010 wordsOperandsLDMIN(––)0300000005004010DM00103F2ADM001151C3DM0012E02ADM00137C9FDM00142A20DM0015A827DM001633BFDM0017E02ADM00182A20DM001994DCDM 05002A20DM 05010014Address of word containing maximum value: 0014Minimum valueMinimum valueIf there are two words containingthe minimum value, the one foundfirst will be stored in DM 0501.7-23-4 AVERAGE VALUE – AVG(––)Ladder SymbolsAVG(––)Operand Data AreasS: Source wordIR, SR, AR, DM, HR, TC, LRSN: Number of cyclesNIR, SR, AR, DM, HR, TC, LR, #DD: First destination wordIR, SR, AR, DM, HR, LRLimitationsThis instruction is available in the CPM2A/CPM2C only.S must be hexadecimal.N must be BCD from #0001 to #0064.D and D+N+1 must be in the same data area.DM 6144 to DM 6655 cannot be used for S, N, or D to D+N+1.DescriptionAVG(––) is used to calculate the average value of S over N cycles.When the execution condition is OFF, AVG(––) is not executed.Each time that AVG(––) is executed, the content of S is stored in words D+2 toD+N+1.
On the first execution, AVG(––) writes the content of S to D+2; on thesecond execution it writes the content of S to D+3, etc. On the Nth execution,446Section 7-23Special Math InstructionsAVG(––) writes the content of S is stored in D+N+1, AVG(––) calculates the average value of the values stored in D+2 to D+N+1, and writes the average to D.The following diagram shows the function of words D to D+N+1.DD+1D+2D+3Average value (after N or more executions)Used by the system.Content of S from the 1st execution of AVG(––)Content of S from the 2nd execution of AVG(––)D+N+1Content of S from the Nth execution of AVG(––)PrecautionsThe average value is calculated in binary. Be sure that the content of S is inbinary.N must be BCD from #0001 to #0064. If the content of N ≥ #0065, AVG(––) willoperate with N=64.The average value will be rounded off to the nearest integer value.
(0.5 isrounded up to 1.)Set the contents of D+1 to #0000 to execute AVG(––) from the first scan.FlagsER:Indirectly addressed DM word is non-existent. (Content of *DM word isnot BCD, or the DM area boundary has been exceeded.)One or more operands have been set incorrectly.D and D+N+1 are not in the same data area.ExampleIn the following example, the content of IR 200 is set to #0000 and then incremented by 1 each cycle.
For the first two cycles, AVG(––) moves the content ofIR 200 to DM 1002 and DM 1003. On the third and later cycles AVG(––) calcu-447Section 7-23Special Math Instructionslates the average value of the contents of DM 1002 to DM 1004 and writes thataverage value to DM 1000.00001@MOV(21)AddressInstruction0000000001LD@MOV(21)Operands#000020000001#AVG(––)20000002AVG(––)#0003#DMDM 10000000300004CLC(41)000020020000031000CLC(41)ADB(50)ADB(50)#2002000001200#0001200IR 200DM 1000DM 1001DM 1002DM 1003DM 10041st cycle00002nd cycle00013rd cycle00024th cycle00031st cycle00002nd cycle00013rd cycle00014th cycle00020000-----00000001---000000010002000300010002AverageUsed by the system.Previousvalues ofIR 2007-23-5 SUM – SUM(––)Operand Data AreasLadder SymbolsSUM(––)@SUM(––)CCR1R1DDC: Control dataIR, SR, AR, DM, HR, LR, #R1: First word in rangeIR, SR, AR, DM, HR, TC, LRD: First destination wordIR, SR, AR, DM, HR, LRLimitationsThis instruction is available in the CPM2A/CPM2C only.The 3 rightmost digits of C must be BCD between 001 and 999.DM 6144 to DM 6655 cannot be used for D.If bit 14 of C is OFF (setting for BCD data), all data within the range R1 to R1+N–1must be BCD.DescriptionWhen the execution condition is OFF, SUM(––) is not executed.
When theexecution condition is ON, SUM(––) adds either the contents of words R1 toR1+N–1 or the bytes in words R1 to R1+N/2–1 and outputs that value to the destination words (D and D+1). The data can be summed as binary or BCD and willbe output in the same form.
Binary data can be either signed or unsigned.448Section 7-23Special Math InstructionsThe function of bits in C are shown in the following diagram and explained inmore detail below.151413121100C:Number of items in range (N, BCD)Number of words or number of bytes001 to 999First byte (when bit 13 is ON)1 (ON): Rightmost0 (OFF): LeftmostData type1 (ON): Binary0 (OFF): BCDAddition units1 (ON): Bytes0 (OFF): WordsNot used – set to zero.Number of Items in RangeThe number of items within the range (N) is contained in the 3 rightmost digits ofC, which must be BCD between 001 and 999. This number will indicate the number of words or the number of bytes depending the items being summed.Addition UnitsWords will be added if bit 13 is OFF and bytes will be added if bit 13 is ON.If bytes are specified, the range can begin with the leftmost or rightmost byte ofR1.
The leftmost byte of R1 will not be added if bit 12 is ON.R1R1+1R1+2R1+3MSB1357LSB2468The bytes will be added in this order when bit 12 is OFF: 1+2+3+4....The bytes will be added in this order when bit 12 is ON: 2+3+4....Data TypeData within the range is treated as unsigned binary when bit 14 of C is ON and bit15 is OFF, and it is treated as signed binary when both bits 14 and 15 are ON.Data within the range is treated as BCD when bit 14 of C is OFF, regardless of thestatus of bit 15.FlagsER:Indirectly addressed DM word is non-existent. (Content of *DM word isnot BCD, or the DM area boundary has been exceeded.)R1 and R1+N–1 are not in the same data area.The number of items in C is not BCD between 001 and 999.The data being summed in not BCD when BCD was designated.EQ:ON when the result is zero.449Section 7-24Logic InstructionsExampleIn the following example, the BCD contents of the 8 words from DM 0000 toDM 0007 are added when IR 00001 is ON and the result is written to DM 0010and DM 0011.00001@SUM(––)AddressInstruction0000000001LD@SUM(––)#0008DM 0000Operands00001#DMDMDM 0010DM 0000DM 0001DM 0002DM 0003DM 0004DM 0005DM 0006DM 000700010002000300040005000600070008DM 0010DM 0011000800000010003600007-24 Logic Instructions7-24-1 COMPLEMENT – COM(29)Ladder SymbolsOperand Data AreasCOM(29)@COM(29)WdWdWd: Complement wordIR, SR, AR, DM, HR, LRLimitationsDM 6144 to DM 6655 cannot be used for Wd.DescriptionWhen the execution condition is OFF, COM(29) is not executed.
When theexecution condition is ON, COM(29) clears all ON bits and sets all OFF bits inWd.PrecautionsThe complement of Wd will be calculated every cycle if the undifferentiated formof COM(29) is used. Use the differentiated form (@COM(29)) or combineCOM(29) with DIFU(13) or DIFD(14) to calculate the complement just once.15ExampleOriginal1000011001100110015Complement 0Flags450100110011001100110ER: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.Section 7-24Logic Instructions7-24-2 LOGICAL AND – ANDW(34)Operand Data AreasLadder SymbolsI1: Input 1IR, SR, AR, DM, HR, TC, LR, #ANDW(34)@ANDW(34)I1I1I2I2RRI2: Input 2IR, 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, ANDW(34) is not executed.
When theexecution condition is ON, ANDW(34) logically AND’s the contents of I1 and I2bit-by-bit and places the result in R.15Example1I10000110011001100150I20010101010101010150RFlags1100001000100010001ER: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-24-3 LOGICAL OR – ORW(35)Operand Data AreasI1: Input 1Ladder SymbolsIR, SR, AR, DM, HR, TC, LR, #LimitationsORW(35)@ORW(35)I1I1I2I2RRI2: Input 2IR, SR, AR, DM, HR, TC, LR, #R: Result wordIR, SR, AR, DM, HR, LRDM 6144 to DM 6655 cannot be used for R.451Section 7-24Logic InstructionsDescriptionWhen the execution condition is OFF, ORW(35) is not executed.
When theexecution condition is ON, ORW(35) logically OR’s the contents of I1 and I2 bitby-bit and places the result in R.15ExampleI11000011001100110015I20001010101010101015RFlags11100101110111011101ER: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-24-4 EXCLUSIVE OR – XORW(36)Operand Data AreasI1: Input 1Ladder SymbolsIR, SR, AR, DM, HR, TC, LR, #XORW(36)@XORW(36)I1I1I2I2RRI2: Input 2IR, 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, XORW(36) is not executed.