The text of a manual · part 33 of 68
Programmable Controllers C200HX-CPU-ZE, C200HG-CPU-ZE, C200HE-CPU-ZE Operation Manual: SECTION 5 Instruction Set, pages 294 to 303
Pages 294 to 303 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 294
Section 5-21
Binary Calculations
In the case below, 25,321 +(–13,253) = 12,068 (62E9 + CC3B = 2F24). Neither OF nor UF are turned ON.
6
+
Au: LR 20 2 E 9
Ad: DM 0010 C C 3 B
2
Ad: DM 0020 F 2 4
Note The status of the CY flag can be ignored when adding signed binary data since it is relevant only in the addition of normal hexadecimal values.
5-21-2 BINARY SUBTRACT – SBB(051) Operand Data Areas Mi: Minuend word (binary)
Ladder Symbols
IR, SR, AR, DM, EM, HR, TC, LR, # SBB(051)
@SBB(051)
Mi
Mi
Su
Su
R
R
Su: Subtrahend word (binary)
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, SBB(051) is not executed. When the execution condition is ON, SBB(051) 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 2’s complement of the actual result is placed in R.
Mi – Su – CY
CY
R
SBB(051) can also be used to subtract signed binary data. The overflow and underflow flags (SR 25404 and SR 25405) indicate whether the result has exceeded the lower or upper limits of the 16-bit signed binary data range. Refer to page 30 for details on signed binary data. Flags
282
ER:
The content of an 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 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).
N:
ON when bit 15 of the result is set to 1.
Page 295
Section 5-21
Binary Calculations Example 1: Normal Data
The following example shows a four-digit subtraction with CY used to place either #0000 or #0001 into R+1 to ensure that any carry is preserved.
TR 1 00001 CLC(041)
SBB(051)
Address
Instruction
00000 00001 00002 00003
LD OUT CLC(041) SBB(051)
001 LR20 HR 21
=R
25504
00004 00005
MOV(021) #0000 HR 22
AND NOT MOV(021)
= R+1
25504 MOV(021) #0001 HR 22
= R+1
00006 00007 00008
LD AND MOV(021)
Operands 00001 TR 1
001 LR 20 HR 21 25504 #0000 HR 22 TR 1 25504 #0001 HR 22
NEG(160) HR21
00009
NEG(160) HR 21 HR 21
HR 21
In the case below, the content of LR 20 (#7A03) and CY are subtracted from IR 001 (#F8C5). The result is stored in HR 21 and the content of HR 22 (#0000) indicates that the result is positive. If the result had been negative, CY would have been set, #0001 would have been placed in HR 22, and the result would have been converted to its 2’s compliment.
0
F
Mi: IR 001 8 C 5
–
7
Su: LR 20 A 0 3
–
0
R+1: HR 22 0 0 0
7
0
0
0
R: HR 21 E C
2
CY = 0 (from CLC(041))
Note The status of the UF and OF flags can be ignored since they are relevant only in the subtraction of signed binary data.
283
Page 296
Section 5-21
Binary Calculations Example 2: Signed Binary Data
In the following example, SBB(051) is used to subtract one 16-bit signed binary value from another. (The 2’s complement is used to express negative values). The effective range for 16-bit signed binary values is –32,768 (8000) to +32,767 (7FFF). The overflow flag (OF: SR 25404) is turned ON if the result exceeds +32,767 (7FFF) and the underflow flag (UF: SR 25405) is turned ON if the result falls below –32,768 (8000).
00000 CLC(041)
SBB(051)
Address
Instruction
00000 00001 00002
LD CLC(041) SBB(051)
LR 20
Operands 00000
LR 20 DM 0010 DM 0020
DM 0010 DM 0020
In the case shown below, 30,020 – (–15,238) = 45,258 (7544 – C47A = 60CA).The OF flag would be turned ON to indicate that this result exceeds the upper limit of the 16-bit signed binary data range. (In other words, the result is a positive value that exceeds 32,767 (7FFF), not a negative number expressed as signed binary data.)
7
–
Mi: LR 20 5 4
4
Su: DM 0010 C 4 7 A
B
R: DM 0020 0 C A
In the case shown below, –30,000 – 3,000 = –33,000 (8AD0 – 0BB8 = 7F18).The UF flag would be turned ON to indicate that this result is below the lower limit of 16-bit signed binary data range. (In other words, the result is a negative number below –32,768 (8000), not a positive number expressed as signed binary data.)
–
8
Mi: LR 20 A D
0
Su: DM 0010 B B 8
7
R: DM 0020 F 1 8
0
The absolute value of the true result (80E8=33,000) can be obtained by taking the 2’s complement of 7F18 using NEG(160). Note The status of the CY flag can be ignored when adding signed binary data since it is relevant only in the addition of normal hexadecimal values.
284
Page 297
Section 5-21
Binary Calculations
5-21-3 BINARY MULTIPLY – MLB(052) Operand Data Areas Md: Multiplicand word (binary)
Ladder Symbols
IR, SR, AR, DM, EM, HR, TC, LR, # MLB(052)
@MLB(052)
Md
Md
Mr
Mr
R
R
Mr: Multiplier word (binary) IR, SR, AR, DM, EM, HR, TC, LR, # R: First result word IR, SR, AR, DM, EM, HR LR
Limitations
R and R+1 must be in the same data area.
Description
When the execution condition is OFF, MLB(052) is not executed. When the execution condition is ON, MLB(052) multiplies the content of Md by the contents of Mr, places the rightmost four digits of the result in R, and places the leftmost four digits in R+1. Md
X
Mr
R +1
R
Precautions
MLB(052) cannot be used to multiply signed binary data. Use MBS(484) instead. Refer to 5-21-7 SIGNED BINARY MULTIPLY – MBS(484) for details.
Flags
ER:
The content of an word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded. ON when the result is 0. ON when bit 15 of R+1 is set to 1.
EQ: N:
5-21-4 BINARY DIVIDE – DVB(053) Operand Data Areas Dd: Dividend word (binary)
Ladder Symbols
IR, SR, AR, DM, EM, HR, TC, LR, # DVB(053)
@DVB(053)
Dd
Dd
Dr
Dr
R
R
Dr: Divisor word (binary)
Description
IR, SR, AR, DM, EM, HR, TC, LR, # R: First result word IR, SR, AR, DM, EM, HR LR
When the execution condition is OFF, DVB(053) is not executed. When the execution condition is ON, DVB(053) divides the content of Dd by the content of Dr and the result is placed in R and R+1: the quotient in R, the remainder in R+1. Quotient R
Dr
Remainder R+1
Dd
285
Page 298
Section 5-21
Binary Calculations Precautions
DVB(053) cannot be used to divide signed binary data. Use DBS(485) instead. Refer to 5-21-9 SIGNED BINARY DIVIDE – DBS(485) for details.
Flags
ER:
Dr contains 0. The content of an word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded.
EQ:
ON when the result is 0.
N:
ON when bit 15 of R is set to 1.
Example 00000 DVB(053) 001
Address
Instruction
00000 00001
LD DVB(053)
Operands
001 LR 0020 HR 05
LR 20 HR 05
0
R+1: HR 06 0 0 2 Remainder (2)
00000
1
Dd: IR 001 0 F 7
0
Dr: LR 20 0 0
3
0
R: HR 05 5 A
7
Quotient (1447)
5-21-5 DOUBLE BINARY ADD – ADBL(480) Operand Data Areas Au: First augend word (binary)
Ladder Symbols
IR, SR, AR, DM, EM, HR, LR, TC ADBL(480)
@ADBL(480)
Au
Au
Ad
Ad
R
R
Ad: First addend word (binary)
Limitations
IR, SR, AR, DM, EM, HR, LR, TC R: First result word IR, SR, AR, DM, EM, HR, LR
Au and Au+1 must be in the same data area, as must Ad and Ad+1, and R and R+1. ADBL(480) is an expansion instruction. A Programming Device can be used to reassign function code 480 to another expansion instruction.
Description
286
When the execution condition is OFF, ADBL(480) is not executed. When the execution condition is ON, ADBL(480)) adds the eight-digit contents of Au+1 and Au, the eight-digit contents of Ad+1 and Ad, and CY, and places the result in R and R+1. CY will be set if the result is greater than FFFF FFFF.
Page 299
Section 5-21
Binary Calculations Au + 1
Au
Ad + 1
Ad
+ CY
CY
R+1
R
ADBL(480) can also be used to add signed binary data. The overflow and underflow flags (SR 25404 and SR 25405) indicate whether the result has exceeded the lower or upper limits of the 32-bit signed binary data range. Refer to page 30 for details on signed binary data. Flags
Example 1: Normal Data
ER:
The content of an 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 greater than FFFF FFFF.
EQ:
ON when the result is 0.
OF:
ON when the result exceeds +2,147,483,647 (7FFF FFFF).
UF:
ON when the result is below –2,147,483,648 (8000 0000).
N:
ON when bit 15 of R is set to 1.
The following example shows an eight-digit addition with CY (SR 25504) used to represent the status of the 9th digit.
00000 CLC(041)
ADBL(480)
Address
Instruction
00000 00001 00002
LD CLC(041) ADBL(480)
000
Operands 00000
000 DM 0020 LR 21
DM 0020 LR 21
14020187 + 00A3F8C5 = 14A5FA4C Au + 1 : 001 1 4 0 2
Au : 000 0 1 8
Ad + 1 : DM 0021
Ad : DM 0020 F 8 C 5
0
0
A
3
7
0
+ R + 1 : LR 22 1 4 A 5
R : LR 21 F A 4
CY (Cleared with CLC(041))
C 0
CY (No carry)
Note The status of the UF and OF flags can be ignored since they are relevant only in the addition of signed binary data. Example 2: Signed Binary Data
In the following example, ADBL(480) is used to add two 32-bit signed binary values and output the 32-bit signed binary result to R and R+1. (The 2’s complement is used to express negative values). The effective range for 32-bit signed binary values is –2,147,483,648 (8000 0000) to +2,147,483,647 (7FFF FFFF). The overflow flag (OF: SR 25404) is turned ON if the result exceeds +2,147,483,647 (7FFF FFFF) and the under-
287
Page 300
Section 5-21
Binary Calculations flow flag (UF: SR 25405) is turned ON if the result falls below –2,147,483,648 (8000 0000). 00000 CLC(041)
ADBL(480)
Address
Instruction
00000 00001 00002
LD CLC(041) ADBL(480)
LR 20
Operands 00000
LR 20 DM 0010 DM 0020
DM 0010 DM 0020
In the case below, 1,799,100,099 + (–282,751,929) = 1,516,348,100 (6B3C167D + EF258C47 = 5A61A2C4). Neither OF nor UF are turned ON. Au + 1 : LR 21 6 B 3 C
Au : LR 20 1 6 7
Ad + 1 : DM 0011
Ad : DM 0010 8 C 4 7
E
F
2
5
+
D
0 R + 1 : DM 0021 5 A 6 1
CY (Cleared with CLC(041))
R : DM 0020 A 2 C 4 0
UF (SR 25405)
0
OF (SR 25404)
Note The status of the CY flag can be ignored when adding signed binary data since it is relevant only in the addition of normal hexadecimal values.
5-21-6 DOUBLE BINARY SUBTRACT – SBBL(481) Operand Data Areas Mi: First minuend word (binary)
Ladder Symbols
IR, SR, AR, DM, EM, HR, TC, LR SBBL(481)
@SBBL(481)
Mi
Mi
Su
Su
R
R
Su: First subtrahend word (binary)
Limitations
IR, SR, AR, DM, EM, HR, TC, LR R: First result word IR, SR, AR, DM, EM, HR, LR
Mi and Mi+1 must be in the same data area, as must Su and Su+1, and R and R+1. SBBL(481) is an expansion instruction. A Programming Device can be used to reassign function code 481 to another expansion instruction.
Description
288
When the execution condition is OFF, SBBL(481) is not executed. When the execution condition is ON, SBBL(481) subtracts CY and the eight-digit value in Su and Su+1 from the eight-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 2’s complement of the actual result is placed in R+1 and R. Use the DOUBLE 2’s COMPLEMENT instructions to convert the 2’s complement to the true result.
Page 301
Section 5-21
Binary Calculations Mi + 1
Mi
Su + 1
Su
– CY
CY
R+1
R
SBBL(481) can also be used to subtract signed binary data. The overflow and underflow flags (SR 25404 and SR 25405) indicate whether the result has exceeded the lower or upper limits of the 32-bit signed binary data range. Refer to page 30 for details on signed binary data. Flags
Example 1: Normal Data
ER:
The content of an 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 plus CY.
EQ:
ON when the result is 0.
OF:
ON when the result exceeds +2,147,483,647 (7FFF FFFF).
UF:
ON when the result is below –2,147,483,648 (8000 0000).
N:
ON when bit 15 of R+1 is set to 1.
In this example, the eight-digit number in IR 002 and IR 001 is subtracted from the eight-digit number in DM 0021 and DM 0020, and the result is output to LR 22 and LR 21. If the result is negative, CY (SR 25504) is turned ON.
00000 CLC(041)
SBBL(481)
Address
Instruction
00000 00001 00002
LD CLC(041) SBBL(481)
001
Operands 00000
001 DM 0020 LR 21
DM 0020 LR 21
14020187 + 00A3F8C5 = 14A5FA4C Au + 1 : 002 1 4 0 2
Au : 001 0 1 8
Ad + 1 : DM 0021
Ad : DM 0020 F 8 C 5
0
0
A
3
–
7
0 R + 1 : LR 22 1 3 5 E
R : LR 21 0 8 C
CY (Cleared with CLC(041))
2 0
CY (No carry)
Note The status of the UF and OF flags can be ignored since they are relevant only in the subtraction of signed binary data. Example 2: Signed Binary Data
In the following example, SBBL(481) is used to subtract one 32-bit signed binary value from another and output the 32-bit signed binary result to R and R+1. The effective range for 32-bit signed binary values is –2,147,483,648 (8000 0000) to +2,147,483,647 (7FFF FFFF). The overflow flag (OF: SR 25404) is turned ON if the result exceeds +2,147,483,647 (7FFF FFFF) and the under-
289
Page 302
Section 5-21
Binary Calculations flow flag (UF: SR 25405) is turned ON is the result falls below –2,147,483,648 (8000 0000). 00000 CLC(041)
SBBL(481)
Address
Instruction
00000 00001 00002
LD CLC(041) SBBL(481)
Operands
001
00000
001 DM 0020 LR 21
DM 0020 LR 21
In the case below, 1,799,100,099 – (–282,751,929) = 2,081,851,958 (6B3C 167D – {EF25 8C47 – 1 0000 0000} = 7C16 8A36). Neither OF nor UF are turned ON.
– –
Au + 1 : 001 6 B 3 C
Au : 000 1 6 7
Ad + 1 : DM 0021
Ad : DM 0020 8 C 4 7
E
F
2
5
D
0 R + 1 : LR 22 7 C 1 6
R : LR 21 8 A 3
CY (Cleared with CLC(041))
6 0
UF (SR 25405)
0
OF (SR 25404)
Note The status of the CY flag can be ignored when adding signed binary data since it is relevant only in the addition of normal hexadecimal values.
5-21-7 SIGNED BINARY MULTIPLY – MBS(484) Operand Data Areas Md: Multiplicand word
Ladder Symbols
IR, SR, AR, DM, EM, HR, TC, LR, # MBS(484)
@MBS(484)
Md
Md
Mr
Mr
R
R
Mr: Multiplier word IR, SR, AR, DM, EM, HR, TC, LR, # R: First result word IR, SR, AR, DM, EM, HR LR
Limitations
R and R+1 must be in the same data area. MBS(484) is an expansion instruction. A Programming Device can be used to reassign function code 484 to another expansion instruction.
Description
MBS(484) multiplies the signed binary content of two words and outputs the 8-digit signed binary result to R+1 and R. The rightmost four digits of the result are placed in R, and the leftmost four digits are placed in R+1. Refer to page 30 for details on signed binary data. Md
X R +1
290
Mr
R
Page 303
Section 5-21
Binary Calculations Flags
Example
ER:
The content of an word containing an indirect DM/EM address is not BCD or the DM/EM area boundary has been exceeded.
EQ:
ON when the result is 0000 0000, otherwise OFF.
N:
ON when bit 15 of R+1 is set to 1.
In the following example, MBS(484) is used to multiply the signed binary contents of IR 001 with the signed binary contents of DM 0020 and output the result to LR 21 and LR 22.
00000 MBS(484) 001
Address
Instruction
00000 00001
LD MBS(484)
Operands
001 DM 0020 LR 21
DM 0020 LR 21
X F
R+1: LR 22 F A A
00000
1
Md: 001 5 B
1
(5,553)
F
Mr: DM 0020 C 1 3
(–1,005)
D
R: LR 21 8 2
3
(–5,580,765)
5-21-8 DOUBLE SIGNED BINARY MULTIPLY – MBSL(482) Operand Data Areas Md: First multiplicand word
Ladder Symbols
IR, SR, AR, DM, EM, HR, TC, LR MBSL(482)
@MBSL(482)
Md
Md
Mr
Mr
R
R
Mr: First multiplier word
Limitations
IR, SR, AR, DM, EM, HR, TC, LR R: First result word IR, SR, AR, DM, EM, HR LR
Md and Md+1 must be in the same data area, as must Mr and Mr+1, and R through R+3. MBSL(482) is an expansion instruction. A Programming Device can be used to reassign function code 482 to another expansion instruction.
Description
MBSL(482) multiplies the 32-bit (8-digit) signed binary data in Md+1 and Md with the 32-bit signed binary data in Mr+1 and Mr, and outputs the 16-digit signed binary result to R+3 through R. Refer to page 30 for details on signed binary data.
x R+3
R+2
Md + 1
Md
Mr + 1
Mr
R+1
R
291