The text of a manual · part 28 of 60
C200HX/C200HG/C200HE Programmable Controllers Operation Manual, pages 264 to 273
Pages 264 to 273 of 586
The original document is the PDF (3.4 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.
For the Omron C200HE-CPU42-E
Page 264
Section 5-20
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(41)
SBB(51)
Address
Instruction
00000 00001 00002 00003
LD OUT CLC(41) SBB(51)
Operands TR
001 LR20 HR 21
LR HR
=R
25504
00004 00005
MOV(21) #0000 HR 22
AND NOT MOV(21)
= R+1
25504 MOV(21) #0001 HR 22
= R+1
00006 00007 00008
LD AND MOV(21)
NEG(––) HR21
00009
00001 1
001 20 21 25504
# HR TR
0000 22 1 25504
# HR
0001 22
HR HR
21 21
NEG(––)
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(41))
Note The status of the UF and OF flags can be ignored since they are relevant only in the subtraction of signed binary data.
246
Page 265
Section 5-20
Binary Calculations Example 2: Signed Binary Data
In the following example, SBB(51) 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(41)
SBB(51)
Address
Instruction
00000 00001 00002
LD CLC(41) SBB(51)
LR 20
Operands 00000
LR DM DM
DM 0010 DM 0020
20 0010 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(––). 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.
247
Page 266
Section 5-20
Binary Calculations
5-20-3 BINARY MULTIPLY – MLB(52) Operand Data Areas Md: Multiplicand word (binary)
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR, # MLB(52)
@MLB(52)
Md
Md
Mr
Mr
R
R
Mr: Multiplier word (binary) IR, SR, AR, DM, HR, TC, LR, # R: First result word IR, SR, AR, DM, HR LR
Limitations
R and R+1 must be in the same data area.
Description
When the execution condition is OFF, MLB(52) is not executed. When the execution condition is ON, MLB(52) 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(52) cannot be used to multiply signed binary data. Use MBS(––) instead. Refer to 5-20-7 SIGNED BINARY MULTIPLY – MBS(––) for details.
Flags
ER:
Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM 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-20-4 BINARY DIVIDE – DVB(53) Operand Data Areas Dd: Dividend word (binary)
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR, # DVB(53)
@DVB(53)
Dd
Dd
Dr
Dr
R
R
Dr: Divisor word (binary)
Description
IR, SR, AR, DM, HR, TC, LR, # R: First result word IR, SR, AR, DM, HR LR
When the execution condition is OFF, DVB(53) is not executed. When the execution condition is ON, DVB(53) 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
248
Dd
Remainder R+1
Page 267
Section 5-20
Binary Calculations Precautions
DVB(53) cannot be used to divide signed binary data. Use DBS(––) instead. Refer to 5-20-9 SIGNED BINARY DIVIDE – DBS(––) for details.
Flags
ER:
Dr contains 0. Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.) ON when the result is 0. ON when bit 15 of R is set to 1.
EQ: N: Example 00000
DVB(53) 001
Address
Instruction
00000 00001
LD DVB(53)
Operands 00000
LR 20
LR HR
HR 05
R+1: HR 06 0 0 2
0
Remainder (2)
1
Dd: IR 001 0 F 7
0
Dr: LR 20 0 0
3
0
R: HR 05 5 A
7
001 0020 05
Quotient (1447)
5-20-5 DOUBLE BINARY ADD – ADBL(––) Operand Data Areas Au: First augend word (binary)
Ladder Symbols
IR, SR, AR, DM, HR, LR ADBL(––)
@ADBL(––)
Au
Au
Ad
Ad
R
R
Ad: First addend word (binary) IR, SR, AR, DM, HR, LR R: First result word IR, SR, AR, DM, HR, LR
Limitations
Au and Au+1 must be in the same data area, as must Ad and Ad+1, and R and R+1.
Description
When the execution condition is OFF, ADBL(––) is not executed. When the execution condition is ON, ADBL(––)) 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. Au + 1
Au
Ad + 1
Ad
+ CY
CY
R+1
R
249
Page 268
Section 5-20
Binary Calculations
ADBL(––) 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 27 for details on signed binary data. Flags
Example 1: Normal Data
ER:
Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM 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(41)
ADBL(––)
Address
Instruction
00000 00001 00002
LD CLC(41) ADBL(––)
Operands 00000
000 DM 0020
DM LR
LR 21
000 0020 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(41))
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(––) 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 underflow flag (UF: SR 25405) is turned ON if the result falls below –2,147,483,648 (8000 0000).
00000 CLC(41)
ADBL(––) LR 20 DM 0010 DM 0020
250
Address
Instruction
00000 00001 00002
LD CLC(41) ADBL(––)
Operands 00000
LR DM DM
20 0010 0020
Page 269
Section 5-20
Binary Calculations
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(41))
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-20-6 DOUBLE BINARY SUBTRACT – SBBL(––) Operand Data Areas Mi: First minuend word (binary)
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR SBBL(––)
@SBBL(––)
Mi
Mi
Su
Su
R
R
Su: First subtrahend word (binary) IR, SR, AR, DM, HR, TC, LR R: First result word IR, SR, AR, DM, HR, LR
Limitations
Mi and Mi+1 must be in the same data area, as must Su and Su+1, and R and R+1.
Description
When the execution condition is OFF, SBBL(––) is not executed. When the execution condition is ON, SBBL(––) 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. Mi + 1
Mi
Su + 1
Su
– CY
CY
R+1
R
SBBL(––) 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 27 for details on signed binary data.
251
Page 270
Section 5-20
Binary Calculations Flags
Example 1: Normal Data
ER:
Indirectly addressed DM word is non-existent. (Content of word is not 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 +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(41)
SBBL(––)
Address
Instruction
00000 00001 00002
LD CLC(41) SBBL(––)
Operands 00000
001 DM 0020
DM LR
LR 21
001 0020 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(41))
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(––) 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 underflow flag (UF: SR 25405) is turned ON is the result falls below –2,147,483,648 (8000 0000).
00000 CLC(41)
SBBL(––)
Address
Instruction
00000 00001 00002
LD CLC(41) SBBL(––)
Operands 00000
001 DM 0020 LR 21
252
DM LR
001 0020 21
Page 271
Section 5-20
Binary Calculations
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(41))
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-20-7 SIGNED BINARY MULTIPLY – MBS(––) Operand Data Areas Md: Multiplicand word
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR, # MBS(––)
@MBS(––)
Md
Md
Mr
Mr
R
R
Mr: Multiplier word IR, SR, AR, DM, HR, TC, LR, # R: First result word IR, SR, AR, DM, HR LR
Limitations
R and R+1 must be in the same data area.
Description
MBS(––) 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 27 for details on signed binary data. Md
X R +1
Flags
Mr
R
ER:
Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM 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.
253
Page 272
Section 5-20
Binary Calculations Example
In the following example, MBS(––) 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(––) 001
Address
Instruction
00000 00001
LD MBS(––)
Operands 00000
DM 0020
DM LR
LR 21
X F
R+1: LR 22 F A A
1
Md: 001 5 B
1
(5,553)
F
Mr: DM 0020 C 1 3
(–1,005)
D
R: LR 21 8 2
3
001 0020 21
(–5,580,765)
5-20-8 DOUBLE SIGNED BINARY MULTIPLY – MBSL(––) Operand Data Areas Md: First multiplicand word
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR MBSL(––)
@MBSL(––)
Md
Md
Mr
Mr
R
R
Mr: First multiplier word IR, SR, AR, DM, HR, TC, LR R: First result word IR, SR, AR, DM, HR LR
Limitations
Md and Md+1 must be in the same data area, as must Mr and Mr+1, and R through R+3.
Description
MBSL(––) 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 27 for details on signed binary data.
x R+3
Flags
254
R+2
Md + 1
Md
Mr + 1
Mr
R+1
R
ER:
Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.)
EQ:
ON when the result is zero (content of R+3 through R all zeroes), otherwise OFF.
N:
ON when bit 15 of R+3 is set to 1.
Page 273
Section 5-20
Binary Calculations Example
In the following example, MBSL(––) is used to multiply the signed binary contents of IR 101 and IR 100 with the signed binary contents of DM 0021 and DM 0020 and output the result to LR 24 through LR 21.
00000
Address
Instruction
00000 00001
LD MBSL(––)
MBSL(––) 100
Operands 00000
DM 0020
DM LR
LR 21
Md+1: IR 101 0 0 8
7
Md: IR 100 9 3 8
(555,320)
Mr+1: DM 0021 F F F 0
A
Mr: DM 0020 8 1 2
(–1,005,550)
R+1: LR 22 C A 5
4
0
X F
R+3: LR 24 F F F
F
R+2: LR 23 F 7 D
F
R: LR 21 5 F
100 0020 21
(–558,402,026,000)
0
5-20-9 SIGNED BINARY DIVIDE – DBS(––) Operand Data Areas Dd: Dividend word
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR, # DBS(––)
@DBS(––)
Dd
Dd
Dr
Dr
R
R
Dr: Divisor word IR, SR, AR, DM, HR, TC, LR, # R: First result word IR, SR, AR, DM, HR LR
Limitations
R and R+1 must be in the same data area.
Description
DBS(––) divides the signed binary content of Dd by the signed binary content of Dr, and outputs the 8-digit signed binary result to R+1 and R. The quotient is placed in R, and the remainder is placed in R+1. Refer to page 27 for details on signed binary data. Quotient R
Dr
Flags
ER:
Remainder R+1
Dd
Dr contains 0. Indirectly addressed DM word is non-existent. (Content of word is not BCD, or the DM area boundary has been exceeded.)
EQ:
ON when the content of R (the quotient) is 0000, otherwise OFF.
N:
ON when bit 15 of R is set to 1.
255