Wiki source code of 09 Rotation and shift

Last modified by Leo Wei on 2022/07/28 03:27

Show last authors
1 = **6.9.1 ROL instruction** =
2
3 **Instruction description**
4
5 (% class="table-bordered" %)
6 |**Name**|**Function**|**Bits(bits)**|**Pulse type**|**Instruction format**|**Step**
7 |ROL|(% rowspan="4" %)Make 16-bit or 32-bit data shift left|16|No|(% rowspan="4" %)ROL D n|5
8 |ROLP|16|Yes|5
9 |DROL|32|No|7
10 |DROLP|32|Yes|7
11
12 The bit pattern of D is rotated n bits to the left on every execution. This instruction is generally used in pulse execution instruction. When the instruction is 32-bit, it occupies the subsequent neighboring address. When the device in D is KnY, KnM or KnS, only K4 (16-bit) and K8 (32-bit) is effective. The status of the last bit rotated is copied to carry flag M8022.
13
14 (% class="table-bordered" %)
15 |(% rowspan="2" %)**Operands**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
16 |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z
17 |D| | | | | | | |√|√|√|√|√|√|√|√|√
18 |n|(% colspan="16" %)Constant, n=1~~16(16bit);n=1~~32(32-bit)
19
20 **Program example**
21
22 (% style="text-align:center" %)
23 [[image:7-8 Rotation and shift_html_f69c69a9d47310d7.jpg||class="img-thumbnail" height="287" width="700"]]
24
25 = **6.9.2 ROR instruction** =
26
27 **Instruction description**
28
29 (% class="table-bordered" %)
30 |**Name**|**Function**|**Bits(bits)**|**Pulse type**|**Instruction format**|**Step**
31 |ROR|(% rowspan="4" %)Make 16-bit or 32-bit data shift right|16|No|(% rowspan="4" %)ROR D n|5
32 |RORP|16|Yes|5
33 |DROR|32|No|7
34 |DRORP|32|Yes|7
35
36 The bit pattern of D is rotated n bits to the right on every execution. This instruction is generally used in pulse execution instruction. When the instruction is 32-bit, it occupies the subsequent neighboring address.
37
38 When the device in D is KnY, KnM or KnS, only K4 (16-bit) and K8 (32-bit) is effective. The status of the last bit rotated is copied to carry flag M8022.
39
40 (% class="table-bordered" %)
41 |(% rowspan="2" %)**Operands**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
42 |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z
43 |D| | | | | | | |√|√|√|√|√|√|√|√|√
44 |n|(% colspan="16" %)Constant, n=1~~16(16bit);n=1~~32(32-bit)
45
46 **Program example**
47
48 (% style="text-align:center" %)
49 [[image:7-8 Rotation and shift_html_97c063aafa8965c3.jpg||class="img-thumbnail" height="287" width="700"]]
50
51 = **6.9.3 RCL instruction** =
52
53 **Instruction description**
54
55 (% class="table-bordered" %)
56 |**Name**|**Function**|**Bits(bits)**|**Pulse type**|**Instruction format**|**Step**
57 |RCL|(% rowspan="4" %)Make 16-bit or 32-bit data shift left with carry|16|No|(% rowspan="4" %)RCL D n|5
58 |RCLP|16|Yes|5
59 |DRCL|32|No|9
60 |DRCLP|32|Yes|9
61
62 The contents of the D are rotated left n bit with the carry flag M8022. This instruction is generally used as pulse execution instruction, i.e. use the RCLP or DRCLP. When the instruction is 32bit, it takes 2 sequential addresses.
63
64 When D is KnY or KnM or KnS, only K4 (16-bit) and K8 (32-bit) are effective.
65
66 (% class="table-bordered" %)
67 |(% rowspan="2" %)**Operands**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
68 |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z
69 |D| | | | | | | |√|√|√|√|√|√|√|√|√
70 |n|(% colspan="16" %)Constant, n=1~~16(16bit);n=1~~32(32-bit)
71
72 **Program example**
73
74 (% style="text-align:center" %)
75 [[image:7-8 Rotation and shift_html_23605217c5370874.jpg||class="img-thumbnail" height="282" width="700"]]
76
77 = **6.9.4 RCR instruction** =
78
79 **Instruction description**
80
81 (% class="table-bordered" %)
82 |**Name**|**Function**|**Bits(bits)**|**Pulse type**|**Instruction format**|**Step**
83 |RCR|(% rowspan="4" %)Make 16-bit or 32-bit data shift right with carry|16|No|(% rowspan="4" %)RCR D n|5
84 |RCRP|16|Yes|5
85 |DRCR|32|No|9
86 |DRCRP|32|Yes|9
87
88 The contents of the D are rotated right n bit with the carry flag M8022. This instruction is generally used as pulse execution instruction, i.e. use the RCLP or DRCRP. When the instruction is 32bit, it takes 2 sequential addresses.
89
90 When D is KnY or KnM or KnS, only K4 (16-bit) and K8 (32-bit) are effective.
91
92 (% class="table-bordered" %)
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 |D| | | | | | | |√|√|√|√|√|√|√|√|√
96 |n|(% colspan="16" %)Constant, n=1~~16(16bit);n=1~~32(32-bit)
97
98 **Program example**
99
100 (% style="text-align:center" %)
101 [[image:7-8 Rotation and shift_html_621a62e748d5a543.jpg||class="img-thumbnail" height="287" width="700"]]
102
103 = **6.9.5 SFTL instruction** =
104
105 **Instruction description**
106
107 (% class="table-bordered" %)
108 |**Name**|**Function**|**Bits(bits)**|**Pulse type**|**Instruction format**|**Step**
109 |SFTL|(% rowspan="2" %)Bit left shift|16|No|(% rowspan="2" %)SFTL S D n1 n2|7
110 |SFTLP|16|Yes|7
111
112 The instruction copies n2 source devices beginning form S to a bit stack of length n1 beginning from D. For every new addition of n2 bits,the existing data within the bit stack is shifted n1 bits to the left. Any bit data moving to a position exceeding the n1 limit is diverted to an overflow area.
113
114 This instruction is generally used as pulse instruction, i.e. SFTLP.
115
116 (% class="table-bordered" %)
117 |(% rowspan="2" %)**Operands**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
118 |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z
119 |S| |√|√|√| | | | | | | | | | | |
120 |D|√|√|√|√| | | | | | | | | | | |
121 |n1|(% colspan="16" %)Constant, n1≤ 1024
122 |n2|(% colspan="16" %)Constant, n2≤ n1
123
124 **Program example**
125
126 (% style="text-align:center" %)
127 [[image:7-8 Rotation and shift_html_fdfb19f8e969cf9f.jpg||class="img-thumbnail" height="226" width="700"]]
128
129 = **6.9.6 SFTR instruction** =
130
131 **Instruction description**
132
133 (% class="table-bordered" %)
134 |**Name**|**Function**|**Bits(bits)**|**Pulse type**|**Instruction format**|**Step**
135 |SFTR|(% rowspan="2" %)Bit right shift|16|No|(% rowspan="2" %)SFTR S D n1 n2|9
136 |SFTRP|16|Yes|9
137
138 The instruction copies n2 source devices beginning form S to a bit stack of length n1 beginning from D. For every new addition of n2 bits, the existing data within the bit stack is shifted n1 bits to the right. Any bit data moving to a position exceeding the n1 limit is diverted to an overflow area.
139
140 This instruction is generally used as pulse instruction, i.e. SFTRP.
141
142 (% class="table-bordered" %)
143 |(% rowspan="2" %)**Operands**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
144 |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z
145 |S| |√|√|√| | | | | | | | | | | |
146 |D|√|√|√|√| | | | | | | | | | | |
147 |n1|(% colspan="16" %)Constant, n1≤ 1024
148 |n2|(% colspan="16" %)Constant, n2≤ n1
149
150 **Program example**
151
152 (% style="text-align:center" %)
153 [[image:7-8 Rotation and shift_html_2db8862fde4312df.jpg||class="img-thumbnail" height="170" width="600"]]
154
155 = **6.9.7 WSFL instruction** =
156
157 **Instruction description**
158
159 (% class="table-bordered" %)
160 |**Name**|**Function**|**Bits(bits)**|**Pulse type**|**Instruction format**|**Step**
161 |WSFL|(% rowspan="2" %)Word left shift|16|No|(% rowspan="2" %)WSFL S D n1 n2|9
162 |WSFLP|16|Yes|9
163
164 The instruction copies n2 source devices to a word stack of length n1. For each addition of n2 words, the existing data within the word stack is shifted n2 words to the left. Any word data moving to a position exceeding the n1 limit is diverted to an overflow area.
165
166 The word shifting operation will occur every time the instruction is processed unless it is modified with either the pulse suffix or a controlled interlock.
167
168 (% class="table-bordered" %)
169 |(% rowspan="2" %)**Operands**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
170 |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z
171 |S| | | | | | | |√|√|√|√|√|√|√| |
172 |D| | | | | | | | |√|√|√|√|√|√| |
173 |n1|(% colspan="16" %)Constant, n1 ≤ 2048
174 |n2|(% colspan="16" %)Constant, n2 ≤ n1
175
176 **Program example**
177
178 (% style="text-align:center" %)
179 [[image:7-8 Rotation and shift_html_bb0b90317653b219.jpg||class="img-thumbnail" height="232" width="700"]]
180
181 = **6.9.8 WSFR instruction** =
182
183 **Instruction description**
184
185 (% class="table-bordered" %)
186 |**Name**|**Function**|**Bits(bits)**|**Pulse type**|**Instruction format**|**Step**
187 |WSFR|(% rowspan="2" %)Word right shift|16|No|(% rowspan="2" %)WSFR S D n1 n2|9
188 |WSFRP|16|Yes|9
189
190 The instruction copies n2 source devices to a word stack of length n1. For each addition of n2 words, the existing data within the word stack is shifted n2 words to the right. Any word data moving to a position exceeding the n1 limit is diverted to an overflow area.
191
192 (% class="table-bordered" %)
193 |(% rowspan="2" %)**Operands**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
194 |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z
195 |S| | | | | | | |√|√|√|√|√|√|√| |
196 |D| | | | | | | | |√|√|√|√|√|√| |
197 |n1|(% colspan="16" %)Constant, n1 ≤ 2048
198 |n2|(% colspan="16" %)Constant, n2 ≤ n1
199
200 **Program example**
201
202 Example 1
203
204 (% style="text-align:center" %)
205 [[image:7-8 Rotation and shift_html_4113ad4f36c97f4c.jpg||class="img-thumbnail" height="197" width="700"]]
206
207 Example 2
208
209 When using a Kn type device, users need to specify the same number of bits.
210
211 (% style="text-align:center" %)
212 [[image:7-8 Rotation and shift_html_5d0aeec735d5390b.jpg||class="img-thumbnail" height="204" width="700"]]
213
214 = **6.9.9 SFRD instruction** =
215
216 **Instruction description**
217
218 (% class="table-bordered" %)
219 |**Name**|**Function**|**Bits**|**Pulse type**|**Instruction format**|**Step**
220 |SFRD|(% rowspan="2" %)Shift read (the reading instruction for controlling FIFO data)|16|No|(% rowspan="2" %)SFRD S D n|7
221 |SFRDP|16|Yes|7
222
223 The source device(S) identifies the head address of the FIFO stack. This instruction reads the first piece of data from the FIFO stack (register S+1), moves all of the data within the stack 'up' one position to fill the read area and decrements the contents of FIFO head address(S) by 1. The read data is written to the destination device (D). When the contents of source device (S) are equal to '0'(zero), i.e. the FIFO stack is empty, the flag M8020 is turned ON.
224
225 This instruction is generally used as pulse instruction, i.e. SFRDP.
226
227 (% class="table-bordered" %)
228 |(% rowspan="2" %)**Operands**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
229 |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z
230 |S| | | | |√|√| |√|√|√|√|√|√|√| |
231 |D| | | | | | | | |√|√|√|√|√|√| |
232 |n|(% colspan="16" %)Constant, n=1~~256(16bit);n=1~~128(32-bit)
233
234 **Program example**
235
236 (% style="text-align:center" %)
237 [[image:7-8 Rotation and shift_html_9be7f0c2e71451ff.jpg||class="img-thumbnail" height="156" width="600"]]
238
239 While X0 is turned from OFF to ON, this instruction executes operations according to the following orders (D10 content remains unchanged).
240
241 1. The content in D2 is transferred to D20;
242 1. D10~~D3 move a bit to right;
243 1. The Indicator (D1) minus 1;
244
245 = **6.9.10 SFWR instruction** =
246
247 **Instruction description**
248
249 (% class="table-bordered" %)
250 |**Name**|**Function**|**Bits**|**Pulse type**|**Instruction format**|**Step**
251 |SFWR|(% rowspan="2" %)Shift write (the writing instruction for controlling FIFO data)|16|No|(% rowspan="2" %)SFWR S D n|7
252 |SFWRP|16|Yes|7
253
254 The contents of source device (S) are written to the FIFO stack. The position of insertion into stack is automatically calculated by the PLC. The destination device (D) is the head address of the FIFO stack. The contents of D identify where the next record will be stored (as an offset from D+1).
255
256 This instruction is generally used as pulse instruction, i.e. SFWRP.
257
258 (% class="table-bordered" %)
259 |(% rowspan="2" %)**Operands**|(% colspan="4" %)**Bit device**|(% colspan="12" %)**Word device**
260 |X|Y|M|S|K|H|E|KnX|KnY|KnM|KnS|T|C|D|V|Z
261 |S| | | | |√|√| |√|√|√|√|√|√|√| |
262 |D| | | | | | | | |√|√|√|√|√|√| |
263 |n|(% colspan="16" %)Constant, 2≤n≤2048
264
265 **Program example**
266
267 (% style="text-align:center" %)
268 [[image:7-8 Rotation and shift_html_6f98d71fd24cc66c.jpg||class="img-thumbnail" height="163" width="600"]]
269
270 When X0 is triggered, the contents of D0 are stored in D2, and the contents of D1 become 1. While X0 is turned from OFF to ON, the contents of D0 are stored in D3, and the contents of D1 become 2, and so on. If the contents of Dl exceed n-1, the instruction is not processed and the carry flag M8022 is set to 1