09 Rotation and shift
6.9.1 ROL instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
ROL | Make 16-bit or 32-bit data shift left | 16 | No | ROL D n | 5 |
ROLP | 16 | Yes | 5 | ||
DROL | 32 | No | 7 | ||
DROLP | 32 | Yes | 7 |
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.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
D | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||||
n | Constant, n=1~16(16bit);n=1~32(32-bit) |
Program example
6.9.2 ROR instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
ROR | Make 16-bit or 32-bit data shift right | 16 | No | ROR D n | 5 |
RORP | 16 | Yes | 5 | ||
DROR | 32 | No | 7 | ||
DRORP | 32 | Yes | 7 |
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.
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.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
D | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||||
n | Constant, n=1~16(16bit);n=1~32(32-bit) |
Program example
6.9.3 RCL instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
RCL | Make 16-bit or 32-bit data shift left with carry | 16 | No | RCL D n | 5 |
RCLP | 16 | Yes | 5 | ||
DRCL | 32 | No | 9 | ||
DRCLP | 32 | Yes | 9 |
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.
When D is KnY or KnM or KnS, only K4 (16-bit) and K8 (32-bit) are effective.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
D | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||||
n | Constant, n=1~16(16bit);n=1~32(32-bit) |
Program example
6.9.4 RCR instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
RCR | Make 16-bit or 32-bit data shift right with carry | 16 | No | RCR D n | 5 |
RCRP | 16 | Yes | 5 | ||
DRCR | 32 | No | 9 | ||
DRCRP | 32 | Yes | 9 |
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.
When D is KnY or KnM or KnS, only K4 (16-bit) and K8 (32-bit) are effective.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
D | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||||
n | Constant, n=1~16(16bit);n=1~32(32-bit) |
Program example
6.9.5 SFTL instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
SFTL | Bit left shift | 16 | No | SFTL S D n1 n2 | 7 |
SFTLP | 16 | Yes | 7 |
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.
This instruction is generally used as pulse instruction, i.e. SFTLP.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | |||||||||||||
D | √ | √ | √ | √ | ||||||||||||
n1 | Constant, n1≤ 1024 | |||||||||||||||
n2 | Constant, n2≤ n1 |
Program example
6.9.6 SFTR instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
SFTR | Bit right shift | 16 | No | SFTR S D n1 n2 | 9 |
SFTRP | 16 | Yes | 9 |
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.
This instruction is generally used as pulse instruction, i.e. SFTRP.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | |||||||||||||
D | √ | √ | √ | √ | ||||||||||||
n1 | Constant, n1≤ 1024 | |||||||||||||||
n2 | Constant, n2≤ n1 |
Program example
6.9.7 WSFL instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
WSFL | Word left shift | 16 | No | WSFL S D n1 n2 | 9 |
WSFLP | 16 | Yes | 9 |
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.
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.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | |||||||||
D | √ | √ | √ | √ | √ | √ | ||||||||||
n1 | Constant, n1 ≤ 2048 | |||||||||||||||
n2 | Constant, n2 ≤ n1 |
Program example
6.9.8 WSFR instruction
Instruction description
Name | Function | Bits(bits) | Pulse type | Instruction format | Step |
WSFR | Word right shift | 16 | No | WSFR S D n1 n2 | 9 |
WSFRP | 16 | Yes | 9 |
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.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | |||||||||
D | √ | √ | √ | √ | √ | √ | ||||||||||
n1 | Constant, n1 ≤ 2048 | |||||||||||||||
n2 | Constant, n2 ≤ n1 |
Program example
Example 1
Example 2
When using a Kn type device, users need to specify the same number of bits.
6.9.9 SFRD instruction
Instruction description
Name | Function | Bits | Pulse type | Instruction format | Step |
SFRD | Shift read (the reading instruction for controlling FIFO data) | 16 | No | SFRD S D n | 7 |
SFRDP | 16 | Yes | 7 |
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.
This instruction is generally used as pulse instruction, i.e. SFRDP.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||||
D | √ | √ | √ | √ | √ | √ | ||||||||||
n | Constant, n=1~256(16bit);n=1~128(32-bit) |
Program example
While X0 is turned from OFF to ON, this instruction executes operations according to the following orders (D10 content remains unchanged).
- The content in D2 is transferred to D20;
- D10~D3 move a bit to right;
- The Indicator (D1) minus 1;
6.9.10 SFWR instruction
Instruction description
Name | Function | Bits | Pulse type | Instruction format | Step |
SFWR | Shift write (the writing instruction for controlling FIFO data) | 16 | No | SFWR S D n | 7 |
SFWRP | 16 | Yes | 7 |
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).
This instruction is generally used as pulse instruction, i.e. SFWRP.
Operands | Bit device | Word device | ||||||||||||||
X | Y | M | S | K | H | E | KnX | KnY | KnM | KnS | T | C | D | V | Z | |
S | √ | √ | √ | √ | √ | √ | √ | √ | √ | |||||||
D | √ | √ | √ | √ | √ | √ | ||||||||||
n | Constant, 2≤n≤2048 |
Program example
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