The text of a manual · part 31 of 68
Programmable Controllers C200HX-CPU-ZE, C200HG-CPU-ZE, C200HE-CPU-ZE Operation Manual: SECTION 5 Instruction Set, pages 274 to 283
Pages 274 to 283 of 613, from Programmable Controllers C200HX-CPU-ZE, C200HG-CPU-ZE, C200HE-CPU-ZE Operation Manual
The original document is the PDF (3.8 MB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
Filed in the catalog under the Omron C200H-SP001 and Omron C200HW-PA204
Page 274
Section 5-19
Symbol Math Instructions binary content of Dr and the result is placed in R and R+1: the quotient in R, the remainder in R+1. Quotient
Remainder
R
Dr
R+1
Dd
DOUBLE SIGNED BINARY DIVIDE When the execution condition is OFF, /L(431) is not executed. When the execution condition is ON, /L(431) divides the signed 8-digit content of Dd and Dd+1 by the signed content of Dr and Dr+1 and the result is placed in R to R+3: the quotient in R and R+1, and the remainder in R+2 and R+3. Remainder R+3
Quotient
R+2
Dr+1
Dr
R+1
R
Dd+1
Dd
UNSIGNED BINARY DIVIDE When the execution condition is OFF, /U(432) is not executed. When the execution condition is ON, /U(432) divides the unsigned content of Dd by the unsigned content of Dr and the result is placed in R and R+1: the quotient in R, the remainder in R+1. Quotient
Remainder
R
Dr
R+1
Dd
DOUBLE UNSIGNED BINARY DIVIDE When the execution condition is OFF, /UL(433) is not executed. When the execution condition is ON, /UL(433) divides the 8-digit unsigned content of Dd and Dd+1 by the unsigned content of Dr and Dr+1 and the result is placed in R to R+3: the quotient in R and R+1, and the remainder in R+2 and R+3. Remainder R+3
Dr+1
R+2
Dr
Quotient R+1
R
Dd+1
Dd
Precautions
Dr (or Dr and Dr+1) must not be all zeros. Instructions will not be executed when ER (Error Flag) is ON.
Flags
ER:
Dr (or Dr and Dr+1) is all zeroes. The content of a word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded.
262
EQ:
The division result is all zeroes in the quotient.
N:
The leftmost bit (MSB) of word R (or word R+1 for “double” instructions) after the division is “1.”
Page 275
Section 5-19
Symbol Math Instructions Example
/L Operation When IR 00000 is ON in the following example, the signed content of DM 0101 and DM 0100 is divided by the signed content of DM 0111 and DM 0110, in eightdigit binary. When the result is obtained, the quotient is output to DM 0121 and DM 0120, and the remainder is output to DM 0123 and DM 0122. /UL Operation When IR 00001 is ON in the following example, the unsigned content of DM 0201 and DM 0200 is divided by the unsigned content of DM 0211 and DM 0210, in eight-digit binary. When the result is obtained, the quotient is output to DM 0221 and DM 0220, and the remainder is output to DM 0223 and DM 0222.
00000 /L(431)
Address
Instruction
DM 0100
00000
LD
DM 0110
00001
/L(431)
Operands 00000
DM 0120
DM 0100
/UL(433)
DM 0120
DM 0110 00001 DM 0200
00002
LD
DM 0210
00003
/UL(433)
00001 DM 0200
DM 0220
DM 0210 DM 0220
5-19-8 BCD Division: /B(434)/ /BL(435) BCD DIVIDE: /B(434) Ladder Symbols
Operand Data Areas Dd: Dividend word
/B(434)
@/B(434)
Dd
Dd
Dr
Dr
R
R
IR, SR, AR, DM, EM, HR, TC, LR, # Dr: Divisor word IR, SR, AR, DM, EM, HR, TC, LR, # R: 1st result word IR, SR, AR, DM, EM, HR, LR
DOUBLE BCD DIVIDE: /BL(435) Ladder Symbols
Operand Data Areas Dd: 1st dividend word
/BL(435)
@/BL(435)
Dd
Dd
Dr
Dr
R
R
IR, SR, AR, DM, EM, HR, TC, LR Dr: 1st divisor word IR, SR, AR, DM, EM, HR, TC, LR R: 1st result word IR, SR, AR, DM, EM, HR, LR
Description
BCD DIVIDE When the execution condition is OFF, /B(434) is not executed and the program moves to the next instruction. When the execution condition is ON, the BCD con-
263
Page 276
Section 5-20
BCD Calculations tent of Dd is divided by the BCD content of Dr and the result is placed in R and R + 1: the quotient in R and the remainder in R + 1. Remainder R+1
Dr
Quotient R
Dd
DOUBLE BCD DIVIDE When the execution condition is OFF, /BL(435) is not executed. When the execution condition is ON, the BCD 8-digit content of Dd and Dd+1 is divided by the BCD content of Dr and Dr+1 and the result is placed in R to R+3: the quotient in R and R+1, and the remainder in R+2 and R+3. Remainder R+3
Dr+1
Quotient
R+2
Dr
R+1
R
Dd+1
Dd
Precautions
Dd and Dr (or Dd, Dd+1, Dr, and Dr+1) must be BCD. If any other data is used, the Error Flag (SR 25503) will turn ON and the instruction will not be executed.
Flags
ER:
Dd and Dr (or Dd, Dd+1, Dr, and Dr+1) are not BCD. The content of a word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded.
EQ:
The division result is all zeroes.
Example
/BL Operation When IR 00001 is ON in the following example, the content of DM 0201 and DM 0200 is divided by the content of DM 0211 and DM 0210, in eight-digit BCD. When the result is obtained, the quotient is output to DM 0221 and DM 0220, and the remainder is output to DM 0223 and DM 0222.
00000 /BL(435) DM 0200 DM 0210 DM 0220
Address
Instruction
00000
LD
00001
/BL(435)
Operands 00000 DM 0200 DM 0210 DM 0220
5-20 BCD Calculations The BCD calculation instructions – INC(038), DEC(039), ADD(030), ADDL(054), SUB(031), SUBL(055), MUL(032), MULL(056), DIV(033), DIVL(057), FDIV(079), and ROOT(072) – all perform arithmetic operations on BCD data. For INC(038) and DEC(039) the source and result words are the same. That is, the content of the source word is overwritten with the instruction result. All other instructions change only the content of the words in which results are placed, i.e., the contents of source words are the same before and after execution of any of the other BCD calculation instructions. STC(040) and CLC(041), which set and clear the carry flag, are included in this group because most of the BCD operations make use of the Carry Flag (0CY) in their results. Binary calculations and shift operations also use CY.
264
Page 277
Section 5-20
BCD Calculations
The addition and subtraction instructions include CY in the calculation as well as in the result. Be sure to clear CY if its previous status is not required in the calculation, and to use the result placed in CY, if required, before it is changed by execution of any other instruction.
5-20-1 INCREMENT – INC(038) Ladder Symbols
Operand Data Areas
INC(038)
@INC(038)
Wd
Wd
Wd: Increment word (BCD) IR, SR, AR, DM, EM, HR, LR
Description
When the execution condition is OFF, INC(038) is not executed. When the execution condition is ON, INC(038) increments Wd, without affecting Carry (CY).
Flags
ER:
Wd is not BCD The content of a word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded.
EQ:
ON when the incremented result is 0.
5-20-2 DECREMENT – DEC(039) Ladder Symbols
Operand Data Areas
DEC(039)
@DEC(039)
Wd
Wd
Wd: Decrement word (BCD) IR, SR, AR, DM, EM, HR, LR
Description
When the execution condition is OFF, DEC(039) is not executed. When the execution condition is ON, DEC(039) decrements Wd, without affecting CY. DEC(039) works the same way as INC(038) except that it decrements the value instead of incrementing it.
Flags
ER:
Wd is not BCD The content of a word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded.
EQ:
ON when the decremented result is 0.
5-20-3 SET CARRY – STC(040) Ladder Symbols STC(040)
@STC(040)
When the execution condition is OFF, STC(040) is not executed.When the execution condition is ON, STC(040) turns ON CY (SR 25504). Note Refer to Appendix C Error and Arithmetic Flag Operation for a table listing the instructions that affect CY.
5-20-4 CLEAR CARRY – CLC(041) Ladder Symbols CLC(041)
@CLC(041)
265
Page 278
Section 5-20
BCD Calculations
When the execution condition is OFF, CLC(041) is not executed.When the execution condition is ON, CLC(041) turns OFF CY (SR 25504). CLEAR CARRY is used to reset (turn OFF) CY (SR 25504) to “0.” CY is automatically reset to “0” when END(001) is executed at the end of each cycle. Note Refer to Appendix C Error and Arithmetic Flag Operation for a table listing the instructions that affect CY.
5-20-5 BCD ADD – ADD(030) Operand Data Areas Au: Augend word (BCD)
Ladder Symbols
IR, SR, AR, DM, EM, HR, TC, LR, # ADD(030)
@ADD(030)
Au
Au
Ad
Ad
R
R
Ad: Addend word (BCD)
Description
Example
R: Result word IR, SR, AR, DM, EM, HR, LR
When the execution condition is OFF, ADD(030) is not executed. When the execution condition is ON, ADD(030) adds the contents of Au, Ad, and CY, and places the result in R. CY will be set if the result is greater than 9999.
Au + Ad + CY Flags
IR, SR, AR, DM, EM, HR, TC, LR, #
CY
R
ER:
Au and/or Ad is not BCD. The content of a word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded.
CY: EQ:
ON when there is a carry in the result. ON when the result is 0.
If 00002 is ON, the program represented by the following diagram clears CY with CLC(041), adds the content of LR 25 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.
TR 0 00002 CLC(041)
ADD(030)
Address
Instruction
00000 00001 00002 00003
LR OUT CLC(041) ADD(030)
LR 25 #6103 DM 0100 25504 MOV(021)
00004 00005
AND MOV(021)
#0001 DM 0101 25504 MOV(021) #0000 DM 0101
266
00006 00007 00008
LD AND NOT MOV(021)
Operands 00002 TR 0
LR 25 #6103 DM 0100 25504 #0001 DM 0101 TR 0 25504 #0000 DM 0101
Page 279
Section 5-20
BCD Calculations
Although two ADD(030) can be used together to perform eight-digit BCD addition, ADDL(054) is designed specifically for this purpose.
5-20-6 DOUBLE BCD ADD – ADDL(054) Operand Data Areas Au: First augend word (BCD)
Ladder Symbols
IR, SR, AR, DM, EM, HR, TC, LR ADDL(054)
@ADDL(054)
Au
Au
Ad
Ad
R
R
Ad: First addend word (BCD) IR, SR, AR, DM, EM, HR, TC, LR R: First result word IR, SR, AR, DM, EM, HR, LR
Limitations
Each of the following pairs must be in the same data area: Au and Au+1, Ad and Ad+1, and R and R+1.
Description
When the execution condition is OFF, ADDL(054) is not executed. When the execution condition is ON, ADDL(054) 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 R and R+1. CY will be set if the result is greater than 99999999. Au + 1
Au
Ad + 1
Ad
+ CY
Flags
ER:
CY R+1
R
Au and/or Ad is not BCD. The content of a word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded.
Example
CY:
ON when there is a carry in the result.
EQ:
ON when the result is 0.
When 00000 is ON, the following program adds two 12-digit numbers, the first contained in LR 20 through LR 22 and the second in DM 0012. The result is placed in LR 10 through HR 13. In the second addition (using ADD(030)), any carry from the first addition is included. The carry from the second addition is
267
Page 280
Section 5-20
BCD Calculations placed in HR 13 by using @ADB(050) (see 5-21-1 BINARY ADD – ADB(050)) with two all-zero constants to indirectly place the content of CY into HR 13. 00000
Address
Instruction
00000 00001 00002
LD CLC(041) @ADDL(054)
Operands
CLC(041) @ADDL(054) LR 20
LR 20 DM 0010 HR 10
DM 0010 HR 10 @ADD(030)
00003
@ADD(030)
LR 22
LR 22 DM 0012 HR 12
DM 0012 HR 12 @ADB(050)
00000
00004
@ADB(050) #0000 #0000 HR 13
#0000 #0000 HR 13
5-20-7 BCD SUBTRACT – SUB(031) Operand Data Areas Mi: Minuend word (BCD)
Ladder Symbols
IR, SR, AR, DM, EM, HR, TC, LR, # SUB(031)
@SUB(031)
Mi
Mi
Su
Su
R
R
Su: Subtrahend word (BCD)
Description
IR, SR, AR, DM, EM, HR, TC, LR, # R: Result word IR, SR, AR, DM, EM, HR, LR
When the execution condition is OFF, SUB(031) is not executed. When the execution condition is ON, SUB(031) 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 complement to the true result, subtract the content of R from zero (see example below).
Mi – Su – CY
CY
R
Note The 2’s COMPLEMENT – NEG(160) instruction can be used to convert binary data only, it cannot be used with BCD data. Flags
ER:
Mi and/or Su is not BCD. The content of a word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded.
! Caution
268
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(041) before executing SUB(031) if its previous status is not required, and check the status of CY after doing a subtraction with SUB(031). If CY is ON as a result of executing SUB(031) (i.e., if the result is negative), 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.
Page 281
Section 5-20
BCD Calculations Example
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. If CY is set by executing SUB(031), the result in HR 20 is subtracted from zero (note that CLC(041) is again required to obtain an accurate result), the result is placed back in HR 20, and HR 2100 is turned ON to indicate a negative result. If CY is not set by executing SUB(031), the result is positive, the second subtraction is not performed, and HR 2100 is not turned ON. HR 2100 is programmed as a self-maintaining bit so that a change in the status of CY will not turn it OFF when the program is recycled. In this example, differentiated forms of SUB(031) are used so that the subtraction operation is performed only once each time 00002 is turned ON. When another subtraction operation is to be performed, 00002 will need to be turned OFF for at least one cycle (resetting HR 2100) and then turned back ON. TR 0
00002 CLC(041)
@SUB(031) 010
First subtraction
Address
Instruction
00000 00001 00002 00003
LD OUT CLC(041) @SUB(031)
DM 0100 HR 20 25504 CLC(041)
@SUB(031) #0000
Second subtraction
00004 00005 00006
AND CLC(041) @SUB(031)
HR 20 HR 20 25504 HR 2100
HR 2100
Turned ON to indicate negative result.
00007 00008 00009 00010
LD AND OR OUT
Operands 00002 TR 0
010 DM 0100 HR 20 25504
#0000 HR 20 HR 20 TR 0 25504 HR 2100 HR 2100
The first and second subtractions for this diagram are shown below using example data for 010 and DM 0100. Note The actual SUB(031) operation involves subtracting Su and CY from 10,000 plus Mi. For positive results the leftmost digit is truncated. For negative results the 10s complement is obtained. The procedure for establishing the correct answer is given below. First Subtraction IR 010 1029 DM 0100 – 3452 CY –0 HR 20 7577 (1029 + (10000 – 3452)) CY 1 (negative result) Second Subtraction 0000 HR 20 –7577 CY –0 HR 20 2423 (0000 + (10000 – 7577)) CY 1 (negative result) In the above case, the program would turn ON HR 2100 to indicate that the value held in HR 20 is negative.
269
Page 282
Section 5-20
BCD Calculations
5-20-8 DOUBLE BCD SUBTRACT – SUBL(055) Operand Data Areas Mi: First minuend word (BCD)
Ladder Symbols
IR, SR, AR, DM, EM, HR, TC, LR SUBL(055)
@SUBL(055)
Mi
Mi
Su
Su
R
R
Su: First subtrahend word (BCD) IR, SR, AR, DM, EM, HR, TC, LR R: First result word IR, SR, AR, DM, EM, HR, LR
Limitations
Each of the following pairs must be in the same data area: Mi and Mi+1, Su and Su+1, and R and R+1.
Description
When the execution condition is OFF, SUBL(055) is not executed. When the execution condition is ON, SUBL(055) subtracts CY and the 8-digit contents of Su and Su+1 from the 8-digit value in Mi and Mi+1, and places the result in R and R+1. 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 the true result, subtract the content of R from zero. Since an 8-digit constant cannot be directly entered, use the BSET(071) instruction (see 5-16-3 BLOCK SET – BSET(071)) to create an 8-digit constant.
Mi + 1
Mi
Su + 1
Su
– CY
CY
R+1
R
Note The DOUBLE 2’s COMPLEMENT – NEGL(161) instruction can be used to convert binary data only, it cannot be used with BCD data.
Flags
ER:
Mi, M+1,Su, and Su+1 are not BCD. The content of a word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded.
CY:
ON when the result is negative, i.e., when Mi is less than Su.
EQ:
ON when the result is 0.
The following example works much like that for single-word subtraction. In this example, however, BSET(071) is required to clear the content of DM 0000 and DM 0001 so that a negative result can be subtracted from 0 (inputting an 8-digit constant is not possible).
270
Page 283
Section 5-20
BCD Calculations Example TR 0 00003 CLC(041)
@SUBL(055) HR 20
First subtraction
120 DM 0100 25504 @BSET(071) #0000 DM 0000 DM 0001 CLC(041)
@SUBL(055) DM 0000
Second subtraction
DM 0100 DM 0100 25504 HR 2100
HR 2100
Turned ON to indicate negative result.
Address
Instruction
00000 00001 00002 00003
LD OUT CLC(041) @SUBL(055)
00004 00005
Operands
Address
00003 TR 0
00006 00007
HR 20 120 DM 0100 25504
AND @BSET(071)
00008 00009 00010 00011
Instruction
Operands
CLC(041) @SUBL(055) DM 0000 DM 0100 DM 0100 TR 0 25504 HR 2100 HR 2100
LD AND OR OUT
#0000 DM 0000 DM 0001
5-20-9 BCD MULTIPLY – MUL(032) Operand Data Areas Md: Multiplicand (BCD)
Ladder Symbols
IR, SR, AR, DM, EM, HR, TC, LR, # MUL(032)
@MUL(032)
Md
Md
Mr
Mr
R
R
Mr: Multiplier (BCD)
Limitations
IR, SR, AR, DM, EM, HR, TC, LR, # R: First result word IR, SR, AR, DM, EM, HR LR
R and R+1 must be in the same data area.
271