The text of a manual · part 33 of 60
SYSMAC CQM1/CPM1/CPM1A/SRM1 Programmable Controllers Programming Manual: SECTION 5 Instruction Set, pages 299 to 308
Pages 299 to 308 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 299
Section 5-20
BCD Calculation Instructions Address
Instruction
00000 00001 00002 00003
LD OUT CLC(41) @SUB(31)
Operands 00002 0
TR
DM HR 00004 00005 00006
00007 00008 00009 00010 00011
AND CLC(41) @SUB(31)
LD LD OR AND LD OUT
# HR HR TR
010 0100 10 25504
HR
0000 10 10 0 25504 1100
HR
1100
The first and second subtractions for this diagram are shown below using example data for 010 and DM 0100. Note The actual SUB(31) 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 10 7577 (1029 + (10000 – 3452)) CY 1 (negative result) Second Subtraction 0000 HR 10 –7577 CY –0 HR 10 2423 (0000 + (10000 – 7577)) CY 1 (negative result) In the above case, the program would turn ON HR 1100 to indicate that the value held in HR 10 is negative.
5-20-5 BCD MULTIPLY – MUL(32) Operand Data Areas Md: Multiplicand (BCD)
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR, # MUL(32)
@MUL(32)
Md
Md
Mr
Mr
R
R
Mr: Multiplier (BCD)
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.
281
Page 300
Section 5-20
BCD Calculation Instructions Description
When the execution condition is OFF, MUL(32) is not executed. When the execution condition is ON, MUL(32) multiplies Md by the content of Mr, and places the result In R and R+1. Md
X R +1
Example
Mr
R
When IR 00000 is ON with the following program, the contents of IR 013 and DM 0005 are multiplied and the result is placed in HR 07 and HR 08. Example data and calculations are shown below the program.
00000 MUL(32) 013 DM 0005
Address
Instruction
00000 00001
LD MUL(32)
HR 07
0
Flags
00000
DM HR
3
Md: IR 013 3 5 6
X
0
Mr: DM 0005 0 2 5
R+1: HR 08 0 0 8
3
R: HR 07 9 0
ER:
Operands
013 0005 07
0
Md and/or Mr is not BCD. 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 there is a carry in the result.
EQ:
ON when the result is 0.
5-20-6 BCD DIVIDE – DIV(33) Operand Data Areas Ladder Symbol
Dd: Dividend word (BCD) IR, SR, AR, DM, HR, TC, LR, #
DIV(33) Dr: Divisor word (BCD) Dd Dr R
Limitations
282
IR, SR, AR, DM, HR, TC, LR, # R: First result word (BCD) IR, SR, AR, DM, HR, LR
R and R+1 must be in the same data area. DM 6143 to DM 6655 cannot be used for R.
Page 301
Section 5-20
BCD Calculation Instructions Description
When the execution condition is OFF, DIV(33) is not executed and the program moves to the next instruction. When the execution condition is ON, Dd is divided by Dr and the result is placed in R and R + 1: the quotient in R and the remainder in R + 1. Remainder
Quotient
R+1
R
Dr
Flags
ER:
Dd
Dd or Dr is not in BCD. 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 result is 0.
When IR 00000 is ON with the following program, the content of IR 216 is divided by the content of HR 09 and the result is placed in DM 0017 and DM 0018. Example data and calculations are shown below the program.
00000 DIV(33) 216
Address
Instruction
00000 00001
LD DIV(33)
Operands 00000
HR 09 DM 0017
1
0
Quotient
Remainder
R: DM 0017 1 5 0
R + 1: DM 0018 0 0 0 2
Dd: HR 09 0 0 3
3
HR DM
216 09 0017
Dd: IR 216 4 5 2
5-20-7 DOUBLE BCD ADD – ADDL(54) Operand Data Areas Au: First augend word (BCD)
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR ADDL(54)
@ADDL(54)
Au
Au
Ad
Ad
R
R
Ad: First addend word (BCD)
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.
283
Page 302
Section 5-20
BCD Calculation Instructions Description
When the execution condition is OFF, ADDL(54) is not executed. When the execution condition is ON, ADDL(54) 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. Indirectly addressed DM word is non-existent. (Content of DM word is not BCD, or the DM 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 section adds two 12-digit numbers, the first contained in LR 00 through LR 02 and the second in DM 0010 through DM 0012. The result is placed in HR 10 through HR 13. The rightmost 8 digits of the two numbers are added using ADDL(54), i.e., the contents of LR 00 and LR 01 are added to DM 0010 and DM 0011 and the results is placed in HR 10 and HR 11. The second addition adds the leftmost 4 digits of each number using ADD(30), and includes any carry from the first addition. The last instruction, ADB(50) (see 5-21-1 BINARY ADD – ADB(50)) adds two allzero constants to place any carry from the second addition into HR 13.
00000
Address
Instruction
00000 00001 00002
LD CLC(41) @ADDL(54)
Operands
CLC(41) @ADDL(54) LR 00 DM 0010 HR 10 @ADD(30)
00003
DM 0012 HR 12
#0000 #0000 HR 13
284
00004
LR DM HR
00 0010 10
LR DM HR
02 0012 12
# # HR
0000 0000 13
@ADD(30)
LR 02
@ADB(50)
00000
@ADB(50)
Page 303
Section 5-20
BCD Calculation Instructions
5-20-8 DOUBLE BCD SUBTRACT – SUBL(55) Operand Data Areas Mi: First minuend word (BCD)
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR, # SUBL(55)
@SUBL(55)
Mi
Mi
Su
Su
R
R
Su: First subtrahend word (BCD) IR, SR, AR, DM, HR, TC, LR, # R: First result word IR, SR, AR, DM, HR, LR
Limitations
DM 6143 to DM 6655 cannot be used for R.
Description
When the execution condition is OFF, SUBL(55) is not executed. When the execution condition is ON, SUBL(55) 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(71) instruction (see 5-17-4 BLOCK SET – BSET(71)) to create an 8-digit constant. Mi + 1
Mi
Su + 1
Su
– CY
Flags
ER:
CY
R+1
R
Mi, M+1,Su, or Su+1 are not BCD. Indirectly addressed DM word is non-existent. (Content of DM word is not BCD, or the DM area boundary has been exceeded.)
Example
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(71) is required to clear the content of DM 0000 and
285
Page 304
Section 5-20
BCD Calculation Instructions
DM 0001 so that a negative result can be subtracted from 0 (inputting an 8-digit constant is not possible). TR 0 00003 CLC(41)
First subtraction
@SUBL(55) HR 00 120 DM 0100 25504 @BSET(71) #0000 DM 0000 DM 0001 CLC(41)
Second subtraction
@SUBL(55) DM 0000 DM 0100 DM 0100 25504 HR 0100
HR 0100
Turned ON to indicate negative result.
Address
Instruction
Operands
00000 00001 00002 00003
LD OUT CLC(41) @SUBL(55)
TR
HR DM 00004 00005
AND @BSET(71) # DM DM
Address
00003 0
Instruction
00006 00007
00 120 0100 25504
00008 00009 00010 00011 00012
0000 0000 0001
Operands
CLC(41) @SUBL(55)
LD LD OR AND LD OUT
DM DM DM TR HR
0000 0100 0100 0 25504 0100
HR
0100
5-20-9 DOUBLE BCD MULTIPLY – MULL(56) Operand Data Areas Md: First multiplicand word (BCD)
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR MULL(56)
@MULL(56)
Md
Md
Mr
Mr
R
R
Mr: First multiplier word (BCD)
286
IR, SR, AR, DM, HR, TC, LR R: First result word IR, SR, AR, DM, HR LR
Page 305
Section 5-20
BCD Calculation Instructions Limitations
DM 6141 to DM 6655 cannot be used for R.
Description
When the execution condition is OFF, MULL(56) is not executed. When the execution condition is ON, MULL(56) multiplies the eight-digit content of Md and Md+1 by the content of Mr and Mr+1, and places the result in R to R+3.
x R+3
Flags
ER:
R+2
Md + 1
Md
Mr + 1
Mr
R+1
R
Md, Md+1,Mr, or Mr+1 is not BCD. 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 there is a carry in the result.
EQ:
ON when the result is 0.
5-20-10 DOUBLE BCD DIVIDE – DIVL(57) Operand Data Areas Dd: First dividend word (BCD)
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR DIVL(57)
@DIVL(57)
Dd
Dd
Dr
Dr
R
R
Dr: First divisor word (BCD) IR, SR, AR, DM, HR, TC, LR R: First result word IR, SR, AR, DM, HR LR
Limitations
DM 6141 to DM 6655 cannot be used for R.
Description
When the execution condition is OFF, DIVL(57) is not executed. When the execution condition is ON, DIVL(57) the eight-digit content of Dd and D+1 is divided by the content of Dr and Dr+1 and the result is placed in R to R+3: the quotient in R and R+1, the remainder in R+2 and R+3. Remainder R+3
Dr+1
Flags
ER:
R+2
Dr
Quotient R+1
R
Dd+1
Dd
Dr and Dr+1 contain 0. Dd, Dd+1, Dr, or Dr+1 is not BCD. 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.
287
Page 306
Section 5-20
BCD Calculation Instructions
5-20-11 SQUARE ROOT – ROOT(72) Ladder Symbols
Operand Data Areas Sq: First source word (BCD)
ROOT(72)
@ROOT(72)
Sq
Sq
R
R
IR, SR, AR, DM, HR, TC, LR R: Result word
Limitations
IR, SR, AR, DM, HR, LR,
This instruction is available in the CQM1 only. DM 6144 to DM 6655 cannot be used for R. When the execution condition is OFF, ROOT(72) is not executed. When the execution condition is ON, ROOT(72) computes the square root of the eight-digit content of Sq and Sq+1 and places the result in R. The fractional portion is truncated.
Description
R
Sq+1
Flags
ER:
Sq
Sq is not BCD. 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 result is 0.
The following example shows how to take the square root of an eight digit number. The result is a four-digit number, with the remainder rounded off. and then round the result. In this example, √63250561 = 7953.0221..., which is rounded off to 7953.
00000 @ROOT(72) DM 0000 001
DM 0001 6 3 2 5
0
DM 0000 5 6 1
63,250,561 = 7953.0221 (The remainder is rounded off.) 7 9
288
001 5
3
Address
Instruction
00000 00001
LD @ROOT(72)
Operands 00000 DM
0000 001
Page 307
Section 5-21
Binary Calculation Instructions
5-21 Binary Calculation Instructions 5-21-1 BINARY ADD – ADB(50) Operand Data Areas Au: Augend word (binary)
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR, # ADB(50)
@ADB(50)
Au
Au
Ad
Ad
R
R
Ad: Addend word (binary) IR, SR, AR, DM, HR, TC, LR, # R: Result word IR, SR, AR, DM, HR, LR
Limitations
DM 6144 to DM 6655 cannot be used for R.
Description
When the execution condition is OFF, ADB(50) is not executed. When the execution condition is ON, ADB(50) adds the contents of Au, Ad, and CY, and places the result in R. CY will be set if the result is greater than FFFF.
Au + Ad + CY
CY
R
ADB(50) can also be used to add signed binary data. With the CPM1A, and SRM1, the underflow and overflow 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. 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 greater than FFFF. ON when the result is 0. ON when the result exceeds +32,767 (7FFF). only) ON when the result is below –32,768 (8000). only)
The following example shows a four-digit addition with CY used to place either #0000 or #0001 into R+1 to ensure that any carry is preserved. TR 0
00000 CLC(41)
ADB(50)
Address
Instruction
00000 00001 00002 00003
LD OUT CLC(41) ADB(50)
Operands TR
010 DM 0100 HR 10
=R
25504
00004 00005
MOV(21) #0000 HR 11
DM HR AND NOT MOV(21)
= R+1
25504 MOV(21) #0001 HR 11
= R+1
00006 00007 00008
LD AND MOV(21)
00000 0
010 0100 10 25504
# HR TR
0000 11 0 25504
# HR
00001 11
289
Page 308
Section 5-21
Binary Calculation Instructions
In the case below, A6E2 + 80C5 = 127A7. The result is a 5-digit number, so CY (SR 25504) = 1, and the content of R + 1 becomes #0001.
0
A
Au: IR 010 6 E 2
+
8
Ad: DM 0100 0 C 5
R+1: HR 11 0 0 1
2
R: HR 10 7 A
7
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-2 BINARY SUBTRACT – SBB(51) Operand Data Areas Mi: Minuend word (binary)
Ladder Symbols
IR, SR, AR, DM, HR, TC, LR, # SBB(51)
@SBB(51)
Mi
Mi
Su
Su
R
R
Su: Subtrahend word (binary) IR, SR, AR, DM, HR, TC, LR, # R: Result word IR, SR, AR, DM, HR, LR
Limitations
DM 6144 to DM 6655 cannot be used for R.
Description
When the execution condition is OFF, SBB(51) is not executed. When the execution condition is ON, SBB(51) 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(51) can also be used to subtract signed binary data. With CPM1A, and SRM1, the underflow and overflow 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. Flags
Example
290
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 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). only)
UF:
ON when the result is below –32,768 (8000). only)
The following example shows a four-digit subtraction. When IR 00001 is ON, the content of LR 00 and CY are subtracted from the content of IR 002 and the result is written to HR 01.