The text of a manual · part 34 of 60
SYSMAC CQM1/CPM1/CPM1A/SRM1 Programmable Controllers Programming Manual: SECTION 5 Instruction Set, pages 309 to 318
Pages 309 to 318 of 520, from SYSMAC CQM1/CPM1/CPM1A/SRM1 Programmable Controllers Programming Manual
The original document is the PDF (2.1 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 CQM1-CPU21
Page 309
Section 5-21
Binary Calculation Instructions
CY is turned ON if the result is negative. If normal data is being used, a negative result (signed binary) must be converted to normal data using NEG(––). Refer to 5-19-17 2’s COMPLEMENT – NEG(––) for details.
00001 CLC(41)
SBB(51)
Address
Instruction
00000 00001 00002 00003
LD OUT CLC(41) SBB(51)
Operands TR
00001 1
LR HR
002 00 01
002 LR00 HR 01
In the case below, the content of LR 00 (#7A03) and CY are subtracted from IR 002 (#F8C5). Since the result is positive, CY is 0. If the result had been negative, CY would have been set to 1. For normal (unsigned) data, the result would have to be converted to its 2’s complement.
F
Mi: IR 002 8 C 5
–
7
Su: LR 00 A 0 3
–
0
7
0
0
0
R: HR 01 E C
2
CY = 0 (from CLC(41))
Note For signed binary calculations, the status of the UF and OF flags indicate whether the result has exceeded the signed binary data range (–32,768 (8000) to +32,767 (7FFF)). only)
5-21-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)
Limitations
IR, SR, AR, DM, HR, TC, LR, # R: First result word IR, SR, AR, DM, HR LR
DM 6143 to DM 6655 cannot be used for R. MLB(52) cannot be used to multiply signed binary data. In CQM1 PCs, MBS(––) can be used. Refer to 5-21-7 SIGNED BINARY MULTIPLY – MBS(––).
291
Page 310
Section 5-21
Binary Calculation Instructions 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
Flags
R
ER:
Indirectly addressed DM word is non-existent. (Content of DM word is not BCD, or the DM area boundary has been exceeded.)
EQ:
ON when the result is 0.
5-21-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)
Limitations
IR, SR, AR, DM, HR, TC, LR, # R: First result word IR, SR, AR, DM, HR LR
DM 6143 to DM 6655 cannot be used for R. DVB(53) cannot be used to divide signed binary data. In CQM1 PCs, DBS(––) can be used. Refer to 5-21-9 SIGNED BINARY DIVIDE – DBS(––) for details.
Description
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
Flags
ER:
Remainder R+1
Dd
Dr contains 0. Indirectly addressed DM word is non-existent. (Content of DM word is not BCD, or the DM area boundary has been exceeded.)
EQ:
292
ON when the result is 0.
Page 311
Section 5-21
Binary Calculation Instructions
5-21-5 DOUBLE BINARY ADD – ADBL(––) Operand Data Areas Au: First augend word (binary)
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR, # ADBL(––)
@ADBL(––)
Au
Au
Ad
Ad
R
R
Ad: First addend word (binary) IR, SR, AR, DM, HR, TC, LR, # R: First result word IR, SR, AR, DM, HR, LR
Limitations
This instruction is available in the only. Au and Au+1 must be in the same data area, as must Ad and Ad+1, and R and R+1. DM 6142 to DM 6655 cannot be used for R.
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. CY will be set if the result is greater than FFFF FFFF. Au + 1
Au
Ad + 1
Ad
+ CY
CY
R+1
R
ADBL(––) can also be used to add signed binary data. The underflow and overflow 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. Flags
ER:
Indirectly addressed DM word is non-existent. (Content of DM 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).
293
Page 312
Section 5-21
Binary Calculation Instructions Example
The following example shows an eight-digit addition with CY (SR 25504) used to represent the status of the 9th digit. The status of the UF and OF flags indicate whether the result has exceeded the signed binary data range (–2,147,483,648 (8000 0000) to +2,147,483,647 (7FFF FFFF)).
00100 CLC(41)
ADBL(––)
Address
Instruction
00000 00001 00002
LD CLC(41) ADBL(––)
LR 00
DM 0020
Au : LR 00 0 0 0
Ad + 1 : DM 0011
Ad : DM 0010 F F F 0
F
F
F
F
CY 1
R + 1 : DM 0021 7 F F F
Note
20 0010 0020
0
0
+
00100
LR DM DM
DM 0010
Au + 1 : LR 01 8 0 0 0
Operands
CY (Cleared with CLC(41))
R : DM 0020 F F F 0 1
UF (SR 25405)
0
OF (SR 25404)
1. For unsigned binary addition, CY indicates that the sum of the two values exceeds FFFF FFFF. (UF and OF can be ignored.) 2. For signed binary addition, the UF flag indicates that the sum of the two values is below –2,147,483,648 (8000 0000). (CY can be ignored.)
5-21-6 DOUBLE BINARY SUBTRACT – SBBL(––) Operand Data Areas Mi: Minuend word (binary)
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR, # SBBL(––)
@SBB(––)
Mi
Mi
Su
Su
R
R
Su: Subtrahend word (binary)
Limitations
IR, SR, AR, DM, HR, TC, LR, # R: Result word IR, SR, AR, DM, HR, LR
This instruction is available in the only. Mi and Mi+1 must be in the same data area, as must Su and Su+1, and R and R+1. DM 6142 to DM 6655 cannot be used for R.
294
Page 313
Section 5-21
Binary Calculation Instructions
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 NEGL(––) to convert the 2’s complement to the true result.
Description
Mi + 1
Mi
Su + 1
Su
– CY
CY
R+1
R
SBBL(––) can also be used to subtract signed binary data. The underflow and overflow 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. Flags
ER: CY: EQ: OF: UF:
Example
Indirectly addressed DM word is non-existent. (Content of DM word is not BCD, or the DM area boundary has been exceeded.) ON when the result is negative, i.e., when Mi is less than Su plus CY. ON when the result is 0. ON when the result exceeds +2,147,483,647 (7FFF FFFF). ON when the result is below –2,147,483,648 (8000 0000).
The following example shows an eight-digit subtraction with CY (SR 25504) used to indicate a negative result (with unsigned data). The status of the UF and OF flags indicate whether the result has exceeded the signed binary data range (–2,147,483,648 (8000 0000) to +2,147,483,647 (7FFF FFFF)).
00101 CLC(41)
SBBL(––)
Address
Instruction
00000 00001 00002
LD CLC(41) SBBL(––)
LR 02
DM 0022
–
Mi : LR 02 F F F
Su + 1 : DM 0023
Su : DM 0022 F F F 0
F
F
F
F
CY 1
R + 1 : LR 03 8 0 0 0
Note
R : LR 02 0 0 0
22 0012 0022
0
0
–
00101
LR DM DM
DM 0012
Mi + 1 : LR 03 7 F F F
Operands
CY (Cleared with CLC(41))
0 0
UF (SR 25405)
1
OF (SR 25404)
1. For unsigned binary data, CY indicates that the result is negative. Take the 2’s complement using NEGL(––) to obtain the absolute value of the true result. (UF and OF can be ignored.) 2. For signed binary data, the OF flag indicates that the result exceeds +2,147,483,647 (7FFF FFFF). (CY can be ignored.)
295
Page 314
Section 5-21
Binary Calculation Instructions
5-21-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
Limitations
IR, SR, AR, DM, HR, TC, LR, # R: First result word IR, SR, AR, DM, HR LR
This instruction is available in the only. DM 6143 to DM 6655 cannot be used for R.
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. Note Refer to 1-10 Calculating with Signed Binary Data for more details. Md
X
Mr
R +1
Flags
Example
R
ER:
Indirectly addressed DM word is non-existent. (Content of DM word is not BCD, or the DM area boundary has been exceeded.)
EQ:
ON when the result is 0000 0000, otherwise OFF.
In the following example, MBS(––) is used to multiply the signed binary contents of DM 0010 with the signed binary contents of DM 0012 and output the result to DM 0100 and DM 0101.
00100 MBS(––) DM 0010
Address
Instruction
00000 00001
LD MBS(––)
DM 0100
R+1: DM 0101 F F A A
296
00100 DM DM DM
DM 0012
X
Operands
1
Md: DM 0010 5 B 1
(5,553)
F
Mr: DM 0012 C 1 3
(–1,005)
D
R: DM 0100 8 2 3
(–5,580,765)
0010 0012 0100
Page 315
Section 5-21
Binary Calculation Instructions
5-21-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
This instruction is available in the only. Md and Md+1 must be in the same data area, as must Mr and Mr+1. R and R+3 must be in the same data area. DM 6143 to DM 6655 cannot be used for R.
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. Note Refer to 1-10 Calculating with Signed Binary Data for more details.
x R+3
Flags
Example
Md + 1
Md
Mr + 1
Mr
R+1
R
R+2
ER:
Indirectly addressed DM word is non-existent. (Content of DM 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.
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 01.
00000
Address
Instruction
00000 00001
LD MBSL(––)
MBSL(––) 100
Operands 00000
DM 0020
DM LR
LR 01
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 02 C A 5
4
R: LR 01 5 F
0
X F
R+3: LR 04 F F F
F
R+2: LR 03 F 7 D
F
0
100 0020 21
(–55,840,206,000)
297
Page 316
Section 5-21
Binary Calculation Instructions
5-21-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
Limitations
IR, SR, AR, DM, HR, TC, LR, # R: First result word IR, SR, AR, DM, HR LR
This instruction is available in the only. DM 6143 to DM 6655 cannot be used for R.
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. Note Refer to 1-10 Calculating with Signed Binary Data for more details. Quotient R
Dr
Flags
ER:
Remainder R+1
Dd
Dr contains 0. Indirectly addressed DM word is non-existent. (Content of DM word is not BCD, or the DM area boundary has been exceeded.)
EQ: Example
ON when the content of R (the quotient) is 0000, otherwise OFF.
In the following example, DBS(––) is used to divide the signed binary contents of DM 0010 with the signed binary contents of DM 0020 and output the result to LR 21 and LR 02.
00000 DBS(––) DM 0010
Address
Instruction
00000 00001
LD DBS(––)
LR 01
F
R+1: LR 02 F F A
Remainder (–6)
298
00000 DM DM LR
DM 0020
÷
Operands
Dd: DM 0010 D D D A
0
Dr: DM 0020 0 1 A
F
R: LR 01 E B
0
Quotient (–336)
(–8,742)
(26)
(–336 and –6/26)
0010 0020 21
Page 317
Section 5-21
Binary Calculation Instructions
5-21-10 DOUBLE SIGNED BINARY DIVIDE – DBSL(––) Operand Data Areas Dd: Dividend word (binary)
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR, # DBS(––)
@DBS(––)
Dd
Dd
Dr
Dr
R
R
Dr: Divisor word (binary) IR, SR, AR, DM, HR, TC, LR, # R: First result word IR, SR, AR, DM, HR LR
Limitations
This instruction is available in the only. Dd and Dd+1 must be in the same data area, as must Dr and Dr+1. R and R+3 must be in the same data area. DM 6143 to DM 6655 cannot be used for R.
Description
DBS(––) divides the 32-bit (8-digit) signed binary data in Dd+1 and Dd by the 32-bit signed binary data in Dr+1 and Dr, and outputs the 16-digit signed binary result to R+3 through R. The quotient is placed in R+1 and R, and the remainder is placed in R+3 and R+2. Note Refer to 1-10 Calculating with Signed Binary Data for more details. Remainder R+3
Dr+1
Flags
ER:
R+2
Dr
R+1
R
Dd+1
Dd
Dr+1 and Dr contain 0. Indirectly addressed DM word is non-existent. (Content of DM word is not BCD, or the DM area boundary has been exceeded.) ON when the content of R+1 and R (the quotient) is 0, otherwise OFF.
EQ: Example
Quotient
In the following example, DBSL(––) is used to divide 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 01.
00000 DBSL(––) 100
Address
Instruction
00000 00001
LD DBSL(––)
Operands 00000
DM 0020
DM LR
LR 01
÷
F
R+3: LR 04 F F F
F
R+2: LR 03 F F C
Remainder (–4)
Dd+1: IR 101 F 7 A
B
Dd: IR 100 1 5 C
(–8,736,420)
Dr+1: DM 0021 0 0 0 0
0
Dr: DM 0020 0 1 A
(26)
R+1: LR 02 F F A
D
R: LR 01 F 7
F
F
0
100 0020 21
(–336,016 and –4/26)
Quotient (–336)
299
Page 318
Section 5-22
Special Math Instructions
5-22 Special Math Instructions 5-22-1 FIND MAXIMUM – MAX(––) Ladder Symbols
Operand Data Areas C: Control data
MAX(––)
@MAX(––)
C
C
R1
R1
D
D
IR, SR, AR, DM, HR, TC, LR, # R1: First word in range IR, SR, AR, DM, HR, TC, LR D: Destination word IR, SR, AR, DM, HR, LR
Limitations
This instruction is available in the CQM1 only. N must be BCD between 0001 to 9999. R1 and R1+N–1 must be in the same data area. DM 6144 to DM 6655 cannot be used for D.
Description
When the execution condition is OFF, MAX(––) is not executed. When the execution condition is ON, MAX(––) searches the range of memory from R1 to R1+N–1 for the address that contains the maximum value and outputs the maximum value to the destination word (D). If bit 15 of C is ON, MAX(––) identifies the address of the word containing the maximum value in D+1. The address is identified differently for the DM area: 1, 2, 3...
1. For an address in the DM area, the word address is written to C+1. For example, if the address containing the maximum value is DM 0114, then #0114 is written in D+1. 2. 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 maximum value is IR 114 and the first word in the search range is IR 014, then #0100 is written in D+1. If bit 14 of C is ON and more than one address contains the same maximum value, the position of the lowest of the addresses will be output to D+1. The position will be output as the DM address for the DM area, but as an absolute position relative 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 of C, which must be BCD between 001 and 999. When bit 15 of C is OFF, data within the range is treated as unsigned binary and when it is ON the data is treated as signed binary. C:
15 14 13 12 11
00 Number of words in range (N) Not used – set to zero.
Data type 1 (ON): Signed binary 0 (OFF): Unsigned binary
! Caution
300
Output 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 the results will differ depending on the specified data type. Be sure that the correct data type is specified.