Wiki source code of 04 Move and compare

Last modified by Wecon on 2025/09/03 21:03

Show last authors
1 = **CMP instruction** =
2
3 **Instruction description**
4
5 (% border="1" %)
6 |**Name**|**Function**|**Bits(bits)**|**Pulse type**|**Instruction format**|**Step**
7 |CMP|(% rowspan="4" %)Comparison instruction|16|No|(% rowspan="4" %)CMP S,,1,, S,,2,, D|7
8 |CMPP|16|Yes|7
9 |DCMP|32|No|13
10 |DCMPP|32|Yes|13
11
12 This instruction compares two operational variables and outputs the comparison result to a specified bit variable. The operands are all algebra compared according to signed data.
13
14 D will occupy 3 continue bit variables address.
15
16 (% border="1" %)
17 |(% rowspan="2" %)**Operands**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
18 |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z
19 |S,,1,,| | | | |√|√|√|√|√|√|√|√|√|√|√|√
20 |S,,2,,| | | | |√|√|√|√|√|√|√|√|√|√|√|√
21 |D| |√|√|√| | | | | | | | | | | |
22
23 **Program example**
24
25 (% style="text-align:center" %)
26 [[image:7-3Move and compare_html_672fc7a91c81c662.jpg||height="182" width="300" class="img-thumbnail"]]
27
28 When X0=ON, M0 or M1 or M2 will be ON.
29
30 When X0=OFF, CMP will not be executed, M0, M1 and M2 keep the initial state. If user wants to clear the result of comparison, RST or ZRST could be used.
31
32 By series or parallel M0, M1 and M2 to achieve the results of ≤ or ≥ or ≠.
33
34 = **ZCP instruction** =
35
36 **Instruction description**
37
38 (% border="1" %)
39 |(% style="width:87px" %)**Name**|(% style="width:429px" %)**Function**|**Bits**|**Pulse type**|**Instruction format**|**Step**
40 |(% style="width:87px" %)ZCP|(% rowspan="4" style="width:429px" %)Regional comparison|16|No|(% rowspan="4" %)ZCP S,,1,, S,,2,, S D|7
41 |(% style="width:87px" %)ZCPP|16|Yes|7
42 |(% style="width:87px" %)DZCP|32|No|13
43 |(% style="width:87px" %)DZCP|32|Yes|13
44
45 The operation is the same as the CMP instruction, except a single data value (S) is compared against a data range (S,,1,,~~S,,2,,).
46
47 * S is less than S,,1,, and S,,2,, - bit device D is ON
48 * S is equal to or between S,,1,, and S,,2,, - bit device D +1 is ON
49 * S is greater than both S,,1,, and S,,2,, - bit device D +2 is ON
50 * S,,1,,: Lower limit of comparison area
51 * S,,2,,: Upper limit of comparison area
52 * S: Comparison variable
53 * D: Storage cell of comparison result; it will occupy three continuous bit variables.
54
55 (% class="box infomessage" %)
56 (((
57 **✎Note: **If the upper limit is less than the lower limit, the upper limit is considered equal to the lower limit.
58 )))
59
60 (% border="1" %)
61 |(% rowspan="2" %)**Operands**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
62 |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z
63 |S,,1,,| | | | |√|√| |√|√|√|√|√|√|√|√|√
64 |S,,2,,| | | | |√|√| |√|√|√|√|√|√|√|√|√
65 |S| | | | |√|√| |√|√|√|√|√|√|√|√|√
66 |D| |√|√|√| | | | | | | | | | | |
67
68 **Program example**
69
70 (% style="text-align:center" %)
71 [[image:7-3Move and compare_html_c50ce4676b83f0f0.jpg||height="150" width="400" class="img-thumbnail"]]
72
73 When X0=ON, M3 or M4 or M5 will be ON.
74
75 When X0=OFF, ZCP will not be executed, M3, m4 and m5 keep the initial state. If user wants to clear the result of comparison, RST or ZRST could be used.
76
77 = **MOV instruction** =
78
79 **Instruction description**
80
81 (% border="1" %)
82 |(% style="width:99px" %)**Name**|(% style="width:566px" %)**Function**|(% style="width:122px" %)**Bits**|(% style="width:181px" %)**Pulse type**|**Instruction format**|**Step**
83 |(% style="width:99px" %)MOV|(% rowspan="4" style="width:566px" %)Moves data from one storage area to a new storage area|(% style="width:122px" %)16|(% style="width:181px" %)No|(% rowspan="4" %)MOV S D|7
84 |(% style="width:99px" %)MOVP|(% style="width:122px" %)16|(% style="width:181px" %)Yes|7
85 |(% style="width:99px" %)DMOV|(% style="width:122px" %)32|(% style="width:181px" %)No|13
86 |(% style="width:99px" %)DMOVP|(% style="width:122px" %)32|(% style="width:181px" %)Yes|13
87
88 The content of the source device (S) is copied to the destination (D) device when the control input is active. If the MOV instruction is not driven, no operation takes place.
89
90 For 32bit instructions (DMOV), two devices will be copied to the destination device, for example DMOV D1 D5, the result is D1→D5, D2→D6.
91
92 (% border="1" %)
93 |(% rowspan="2" %)**Operands**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
94 |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z
95 |S| | | | |√|√| |√|√|√|√|√|√|√|√|√
96 |D| | | | | | | | |√|√|√|√|√|√|√|√
97
98 **Program example**
99
100 (% style="text-align:center" %)
101 [[image:7-3Move and compare_html_63375e0f97aaffe1.jpg||height="264" width="300" class="img-thumbnail"]]
102
103 When M0 is on, D2=K4, when M0 becomes off, D2 keeps the initial value. Only when user copy another value to D2 or power off the plc or set plc off and on again, the value of D2 will change.
104
105 = **SMOV instruction** =
106
107 **Instruction description**
108
109 (% border="1" %)
110 |**Name**|**Function**|**Bit(bits)**|**Pulse type**|**Instruction format**|**Step**
111 |SMOV|(% rowspan="2" %)Shift Move|16|No|(% rowspan="2" %)SMOV S M,,1,, M,,2,, D n|11
112 |SMOVP|16|Yes|11
113
114 This instruction copies a specified number of digits from a 4 digit decimal source (S) and places them at a specified location within a destination (D) number (also a 4 digit decimal). The existing data in the destination is overwritten.
115
116 * M,,1,, - The source position of the 1st digit to be moved
117 * M,,2,, - The number of source digits to be moved
118 * n- The destination position for the first digit
119
120 Allows BCD numbers to be manipulated in exactly the same way as the ‘normal’ SMOV manipulates decimal numbers, i.e. This instruction copies a specified number of digits from a 4 digit BCD source (S) and places them at a specified location within a destination (D) number (also a 4 digit BCD number).
121
122 To select the BCD mode the SMOV instruction is coupled with special M coil M8168 which is driven ON. Please remember that this is a ‘mode’ setting operation and will be active, i.e. all SMOV instructions will operate in BCD format until the mode is reset, i.e. M8168 is forced OFF.
123
124 (% border="1" %)
125 |(% rowspan="2" %)**Operands**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
126 |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z
127 |S| | | | | | | |√|√|√|√|√|√|√|√|√
128 |M,,1,,| | | | |√|√| | | | | | | | | |
129 |M,,2,,| | | | |√|√| | | | | | | | | |
130 |D| | | | | | | | |√|√|√|√|√|√|√|√
131 |n| | | | |√|√| | | | | | | | | |
132
133 **Program example**
134
135 (% style="text-align:center" %)
136 [[image:7-3Move and compare_html_48fa719e1026dc06.jpg||height="98" width="400" class="img-thumbnail"]]
137
138 (% style="text-align:center" %)
139 [[image:7-3Move and compare_html_e534a9aa917b173f.jpg||height="265" width="500" class="img-thumbnail"]]
140
141 Suppose D8=K1234, D2=K5678, then when m8168 is off (bcd mode), set m2, then the value of D2 becomes K5128.
142
143 When m8168 is on (bin mode) and D8=H04D2=K1234, D2=H162E=K5678, set m2, then D2=H104E=K4174
144
145 = **CML instruction** =
146
147 **Instruction description**
148
149 (% border="1" %)
150 |**Name**|**Function**|**Bits**|**Pulse type**|**Instruction format**|**Step**
151 |CML|(% rowspan="4" %)Copies and inverts the source bit pattern to a specified destination|16|No|(% rowspan="4" %)CML S D|5
152 |CMLP|16|Yes|5
153 |DCML|32|No|13
154 |DCMLP|32|Yes|13
155
156 A copy of each data bit within the source device (S) is inverted and then moved to a designated destination (D).
157
158 This means each occurrence of a ‘1’ in the source data will become a ‘0’ in the destination data while each source digit which is ‘0’ will become a ‘1’. If the destination area is smaller than the source data then only the directly mapping bit devices will be processed.
159
160 (% border="1" %)
161 |(% rowspan="2" %)**Operand**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
162 |**X**|**Y**|**M**|**S**|**K**|**H**|**E**|**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**V**|**Z**
163 |S| | | | |√|√| |√|√|√|√|√|√|√|√|√
164 |D| | | | | | | | |√|√|√|√|√|√|√|√
165
166 **Program example**
167
168 Example 1:
169
170 (% style="text-align:center" %)
171 [[image:7-3Move and compare_html_4000eebfee28cea.jpg||height="76" width="700" class="img-thumbnail"]]
172
173 Example 2:
174
175 (% style="text-align:center" %)
176 [[image:7-3Move and compare_html_4c65a7fd9a7dc666.jpg||height="62" width="400" class="img-thumbnail"]]
177
178 This program is equal to the below ladder diagrams.
179
180 (% style="text-align:center" %)
181 [[image:7-3Move and compare_html_7461c87bb822614f.jpg||height="245" width="600" class="img-thumbnail"]]
182
183 Example 3:
184
185 (% style="text-align:center" %)
186 [[image:7-3Move and compare_html_e2175c6ded744b63.jpg||height="159" width="500" class="img-thumbnail"]]
187
188 = **BMOV instruction** =
189
190 **Instruction description**
191
192 (% border="1" %)
193 |**Name**|**Function**|**Bit**|**Pulse type**|**Instruction format**|**Step**
194 |BMOV|(% rowspan="2" %)Copies a specified block of multiple data elements to a new destination|16|No|(% rowspan="2" %)BMOV S D n|7
195 |BMOVP|16|Yes|7
196
197 A quantity of consecutively occurring data elements could be copied to a new destination. The source data is identified as a device head address (S) and a quantity of consecutive data elements . This is moved to the destination device (D) for the same number of elements .
198
199 When the special variable is M8024=ON, the transmission direction is opposite, i.e. S becomes the destination address, D becomes the source address.
200
201 (% style="text-align:center" %)
202 [[image:7-3Move and compare_html_c645fa580437088e.jpg||height="107" width="500" class="img-thumbnail"]]
203
204 When the operand is bit device, the digit number of S and D need to be the same.
205
206 (% border="1" %)
207 |(% rowspan="2" %)**Operand**|(% colspan="5" %)**Bit device**|(% colspan="13" %)**Word device**
208 |**X**|**Y**|(% colspan="2" %)**M**|**S**|**K**|**H**|**E**|(% colspan="2" %)**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**V**|**Z**
209 |S| |(% colspan="2" %) | | | | |(% colspan="2" %) |√|√|√|√|√|√|√| |
210 |D| |(% colspan="2" %) | | | | |(% colspan="2" %) | |√|√|√|√|√|√| |
211 |n|(% colspan="18" %)Constant n=0 to 512
212
213 **Program example**
214
215 (% style="text-align:center" %)
216 [[image:7-3Move and compare_html_22db5b59455aaf81.jpg||height="80" width="400" class="img-thumbnail"]]
217
218 Result
219
220 (% style="text-align:center" %)
221 [[image:7-3Move and compare_html_495118782198828d.jpg||height="119" width="400" class="img-thumbnail"]]
222
223 = **FMOV instruction** =
224
225 **Instruction description**
226
227 (% border="1" %)
228 |**Name**|**Function**|**Bits**|**Pulse type**|**Instruction format**|**Step**
229 |FMOV|(% rowspan="4" %)Copies a single data device to a range of destination devices|16|No|(% rowspan="4" %)MOV S D n|7
230 |FMOVP|16|Yes|7
231 |DFMOV|32|No|13
232 |DFMOVP|32|Yes|13
233
234 The data stored in the source device (S) is copied to every device within the destination range. The range is specified by a device head address (D) and a quantity of consecutive elements . If the specified number of destination devices exceeds the available space at the destination location, then only the available destination devices will be written to.
235
236 (% border="1" %)
237 |(% rowspan="2" %)**Operands**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
238 |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z
239 |S| | | | | | | |√|√|√|√|√|√|√|√|√
240 |D| | | | | | | | |√|√|√|√|√|√| |
241 |n|(% colspan="16" %)Constant, n=1 to512
242
243 **Program example**
244
245 (% style="text-align:center" %)
246 [[image:7-3Move and compare_html_d9b4a3ac38311c49.jpg||height="79" width="500" class="img-thumbnail"]]
247
248 When M8 is on, k100→D100, k100→D101, k100→D102, k100→D103.
249
250 = **XCH instruction** =
251
252 **Instruction description**
253
254 (% border="1" %)
255 |**Name**|**Function**|**Bits**|**Pulse type**|**Instruction format**|**Step**
256 |XCH|(% rowspan="4" %)Data in the designated devices is exchanged|16|No|(% rowspan="4" %)XCH S D|5
257 |XCHP|16|Yes|5
258 |DXCH|32|No|9
259 |DXCHP|32|Yes|9
260
261 The contents of the two destination devices S and D are swapped, i.e. the complete word devices are exchanged.
262
263 (% border="1" %)
264 |(% rowspan="2" %)**Operands**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
265 |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z
266 |S| | | | | | | | |√|√|√|√|√|√| |
267 |D| | | | | | | | |√|√|√|√|√|√| |
268
269 **Program example**
270
271 (% style="text-align:center" %)
272 [[image:7-3Move and compare_html_fedbe33fa98b559b.png||height="112" width="300" class="img-thumbnail"]]
273
274 Example 1:
275
276 (% style="text-align:center" %)
277 [[image:7-3Move and compare_html_f11050348326c6bf.jpg||height="57" width="300" class="img-thumbnail"]]
278
279 Example 2:
280
281 (% style="text-align:center" %)
282 [[image:7-3Move and compare_html_fbd85cc43fa9377f.png||height="177" width="300" class="img-thumbnail"]]
283
284 (% style="text-align:center" %)
285 [[image:7-3Move and compare_html_28cf590a9d5c90f8.jpg||height="53" width="300" class="img-thumbnail"]]
286
287 This function is equivalent to SWAP the bytes within each word of the designated devices D1 are exchanged when ‘byte mode flag’ M8160 is ON. Please note that the mode will remain active until it is reset, i.e. M8160 is forced OFF.
288
289 = **BCD instruction** =
290
291 **Instruction description**
292
293 (% border="1" %)
294 |**Name**|(% style="width:647px" %)**Function**|(% style="width:86px" %)**Bits**|(% style="width:97px" %)**Pulse type**|(% style="width:305px" %)**Instruction format**|**Step**
295 |BCD|(% rowspan="4" style="width:647px" %)Converts binary numbers to BCD equivalents / Converts floating point data to scientific format|(% style="width:86px" %)16|(% style="width:97px" %)No|(% rowspan="4" style="width:305px" %)BCD S D|5
296 |BCDP|(% style="width:86px" %)16|(% style="width:97px" %)Yes|5
297 |DBCD|(% style="width:86px" %)32|(% style="width:97px" %)No|9
298 |DBCDP|(% style="width:86px" %)32|(% style="width:97px" %)Yes|9
299
300 The binary source data (S) is converted into an equivalent BCD number and stored at the destination device (D).
301
302 If the converted BCD number exceeds the operational ranges of 0 to 9,999 (16-bit operation) and 0 to 99,999,999 (32-bit operation) an error will occur. M8067 will be ON, and D8067 will record the error code.
303
304 (% border="1" %)
305 |(% rowspan="2" %)**Operand**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
306 |**X**|**Y**|**M**|**S**|**K**|**H**|**E**|**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**V**|**Z**
307 |S| | | | | | | |√|√|√|√|√|√|√|√|√
308 |D| | | | | | | |√|√|√|√|√|√|√|√|√
309
310 **Programming example**
311
312 (% style="text-align:center" %)
313 [[image:7-3Move and compare_html_adf65a6fbcb01118.jpg||height="74" width="400" class="img-thumbnail"]]
314
315 The BIN value in D200 is converted to BCD value and the units’ digit is saved in K1Y0 (Y0 to Y3).
316
317 * If D200=H000E (hex) =K14 (decimal), then Y0~~Y3=0100(BIN).
318 * If D200=H0028 (hex) =K40 (decimal), then Y0~~Y3=0000(BIN).
319
320 = **BIN instruction** =
321
322 **Instruction description**
323
324 (% border="1" %)
325 |**Name**|**Function**|**Bits**|**Pulse type**|**Instruction format**|**Step**
326 |**BIN**|(% rowspan="4" %)**Converts BCD umbers to their binary equivalent /Converts scientific format data to floating point format**|**16**|**No**|(% rowspan="4" %)**BIN S D**|**5**
327 |**BINP**|**16**|**Yes**|**5**
328 |**DBIN**|**32**|**No**|**9**
329 |**DBINP**|**32**|**Yes**|**9**
330
331 The BCD source data (S) is converted into an equivalent binary number and stored at the destination device (D). If the source data is not provided in a BCD format an error will occur. This instruction could be used to read in data directly from thumbwheel switches.
332
333 The value of S (BCD) ranges from 0 to 9999(16-bit) and 0 to 99999999(32-bit)
334
335 When the value of D is not BCD, there will be an error, and M8067 will be ON.
336
337 (% border="1" %)
338 |(% rowspan="2" %)**Operand**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
339 |**X**|**Y**|**M**|**S**|**K**|**H**|**E**|**KnX**|**KnY**|**KnM**|**KnS**|**T**|**C**|**D**|**V**|**Z**
340 |S| | | | | | | |√|√|√|√|√|√|√|√|√
341 |D| | | | | | | |√|√|√|√|√|√|√|√|√
342
343 **Program example**
344
345 (% style="text-align:center" %)
346 [[image:7-3Move and compare_html_a99ac786bd9a7c9c.jpg||height="70" width="300" class="img-thumbnail"]]
347
348 When M8 is ON, K1Y0 (BCD value) will be converted into BIN and stored in the D200.