Professional Documents
Culture Documents
Fourth Year
Experiment no.6
Student's No.: 4
Prepared by:
Dr Ammar A. Aldair
Dr Mofeed T. Rashid
(SHR).
7- Rotate To Right
(ROL).
Discussion:
PLC Shift and rotate instructions are often used to track parts on
automated manufacturing lines by shifting either status or values through
data files. The PLC not only uses a fixed pattern of register (word) bits. But
also can easily manipulate and change individual bits. A bit shift register is a
register that allows the shifting of bits through a single register or group of
registers. In the following, there are many types of shift and rotate
instructions:
5.1 Shift Designated Array Elements
The shift with carry instruction (SHIFT_C) behaves the same way
the SHIFT_A instruction does. Figure 5.2 shows the ladder symbol of
this instruction and also the shifting movement for one positive
transition of IN.
SHFT_C SRC:%MB2 SRC:%MB2
BOOL BOOL EN BOOL BOOL
ENO 0 0
1 IN=1 1
CY OUT
Start=2 0 1
{
{Byte, Word, SRC SRC Byte, Word, 1 0
Dword, Lwor d} Dword, 1 1
START Lword} 0 1
UINT
End=5 0 0 OUT=0
UINT END
0 0
UINT N
gh
5.3 Shift R After one pulse Shifting
t Before Shifting
The sh ift
Figure
right5.2 SHIFT_C
instruction ladder
(SHR) symbol
shifts and behavior
the image diagram
of the bit string
Byte, Word, Double word, Long word) assigned to IN (instruction data
input) as N (instruction shifting times) bits number and stores the shifted
result in the instruction output variable OUT. Figure 5.3 highlights the
ladder symbol used and illustrates its operation for
different N values.
IN N OUT
1 64
2 32
3 16
%MB2 4 8
SHR =128 5 4
BOOL EN ENO BOOL 6 2
{Byte,Word, IN OUT {Byte, Word, 7 1
Dword, Lword} 8 0
Dword, Lword}
INT N
The shift let instruction (SHL) does the reverse done by its predecessor
SHR. SHR does the integer division by two, but SHL does the
multiplication by 2. It shifts the image of the bit string IN as N times from
the least significant bit towards the most significant one. Figure 5.4
displays the ladder symbol used and illustrates the instruction
operation for different N values.
SHL
BOOL EN ENO BOOL IN N OUT
{Byte,Word, IN 1 2
OUT {Byte,Word,
Dword,Lword 2 4
Dword,Lword} 3 8
INT N %MB2=1 4 16
5 32
6 64
7 128
8 0
Figure 5.4 SHL ladder symbol and shifting Process as function of N
Figure 5.5 ROTATE_A ladder symbol and behavior for three different configuration.
Figure 5.6 shows the ladder symbol of this shifting instruction and its
behavior under different configurations.
ROTATE_C
BOOL ENO BOOL
EN
{Byte, Word, SRC
Dword, Lword} SRC {Byte, Word,
Dword, Lword}
UINT
STARTOUT END BOOL
UINT N
UINT
Figure 5.6 ROTATE_C ladder symbol and behavior for four different configuration.
The rotate right instruction ( ROR) shifts the image of the input bit
string IN ( Byte, Word, Dword, Lword ) as N ( shifting times ) bits
number, fills the leftmost locations with the values shifted out of the
right most locations such that for M bits string, the least significant bit B0
of IN is rounded to image B(M-N) bit. The modified ( shifted and
rounded) version of the input bit string is stored in the output variable
OUT. Figure 5.7 shows the ladder symbol and enhances the
aforementioned explanation.
ROR
BOOL ENO BOOL
EN
{ Byte, Word, IN { Byte, Word,
Dword, Lword} OUT Dword,
INT Lword}
IN vale {2#10101010}
Bit IN OUT (N=1) OUT (N=2) OUT (N=3)
7 1 OUTB7=INB0=0 OUTB7=INB1=1 OUTB7=INB2=0
6 0 OUTB6=INB7=1 OUTB6=INB0=0 OUTB6=INB1=1
5 1 OUTB5=INB6=0 OUTB5=INB7=1 OUTB5=INB0=0
4 0 OUTB4=INB5=1 OUTB4=INB6=0 OUTB46=INB7=1
3 1 OUTB3=INB4=0 OUTB3=INB5=1 OUTB3=INB6=0
2 0 OUTB2=INB3=1 OUTB2=INB4=0 OUTB2=INB5=1
1 1 OUTB1=INB2=0 OUTB1=INB3=1 OUTB1=INB4=0
0 0 OUTB0=INB1=1 OUTB0=INB2=0 OUTB0=INB3=1
Figure 5.7 ROR ladder symbol and its behavior under different values of
N
The rotate left instruction ( ROL) shifts the image of the input bit
string IN ( Byte, Word, Dword, Lword ) as N bits number, fills the
rightmost locations with the values shifted out of the left most locations
such that for M bits string, the most significant bit B M-1 of IN is rounded to
image BN-1 bit. The modified version of the input bit string is stored in
the output variable OUT. Figure 5.8 shows the ladder symbol and
tabulates the left rotation of %MB3 for different values of N.
ROL
BOOL ENO BOOL
EN
{Byte, Word,
Dword, Lword}
IN {Byte, Word,
OUT Dword, Lword}
INT
N
IN vale=%MB3= {2#10101010}
Bit IN OUT (N=1) OUT (N=2) OUT (N=3)
7 1 OUTB7=INB6=0 OUTB7=INB5=1 OUTB7=INB4=0
6 0 OUTB6=INB5=1 OUTB6=INB4=0 OUTB6=INB3=1
5 1 OUTB5=INB4=0 OUTB5=INB3=1 OUTB5=INB2=0
4 0 OUTB4=INB3=1 OUTB4=INB2=0 OUTB46=INB1=1
3 1 OUTB3=INB2=0 OUTB3=INB1=1 OUTB3=INB0=0
2 0 OUTB2=INB1=1 OUTB2=INB0=0 OUTB2=INB7=1
1 1 OUTB1=INB0=0 OUTB1=INB7=1 OUTB1=INB6=0
0 0 OUTB0=INB7=1 OUTB0=INB6=0 OUTB0=INB5=1
Figure 5.8 ROL ladder symbol and its OUT value as function of N
BOOL
{Any type BOOL
except string }
ny type except string }
{Array of any type
except string}
INT
BOOL
BOOL BOOL
BOOL BOOL
Figure 5.10 LIFO function block.
Procedure:
P1 P2 P3
LS2
LS1
LS1
Fig.5.11