10.13 ---(MCRD) Master Control Relay Deactivate
11 Shift and Rotate Instructions
11.1 Shift Instructions
11.1.1 Overview of Shift Instructions
Description
You can use the Shift instructions to move the contents of input IN bit by bit to the left or the right (see also CPU Registers). Shifting to the left multiplies the contents of input IN by 2 to the power n (2 n ); shifting to the right divides the contents of input IN by 2 to the power n (2 n ). For example, if you shift the binary equivalent of the decimal value 3 to the left by 3 bits, you obtain the binary equivalent of the decimal value 24 in the accumulator. If you shift the binary equivalent of the decimal value 16 to the right by 2 bits, you obtain the binary equivalent of the decimal value 4 in the accumulator.
The number that you supply for input parameter N indicates the number of bits by which to shift. The bit places that are vacated by the Shift instruction are either filled with zeros or with the signal state of the sign bit (a 0 stands for positive and a 1 stands for negative). The signal state of the bit that is shifted last is loaded into the CC 1 bit of the status word. The CC 0 and OV bits of the status word are reset to 0. You can use jump instructions to evaluate the CC 1 bit.
The following shift instructions are available:
• SHR_I Shift Right Integer
• SHR_DI Shift Right Double Integer
• SHL_W Shift Left Word
• SHR_W Shift Right Word
• SHL_DW Shift Left Double Word
• SHR_DW Shift Right Double Word
长沙工控帮教育科技有限公司整理
11.1.2 SHR_I Shift Right Integer
Parameter Data Type Memory Area Description
EN BOOL I, Q, M, L, D Enable input
ENO BOOL I, Q, M, L, D Enable output
IN INT I, Q, M, L, D Value to shift
N WORD I, Q, M, L, D Number of bit positions to shift
OUT INT I, Q, M, L, D Result of shift instruction
Description
SHR_I (Shift Right Integer) is activated by a logic "1" at the Enable (EN) Input. The SHR_I instruction is used to shift bits 0 to 15 of input IN bit by bit to the right. Bits 16 to 31 are not affected. The input N specifies the number of bits by which to shift.
If N is larger than 16, the command acts as if N were equal to 16. The bit positions shifted in from the left to fill vacated bit positions are assigned the logic state of bit 15 (sign bit for the integer). This means these bit positions are assigned "0" if the integer is positive and "1" if the integer is negative. The result of the shift instruction can be scanned at output OUT. The CC 0 bit and the OV bit are set to "0" by SHR_I if N is not equal to 0.
ENO has the same signal state as EN.
1 0 1 0
The vacated places are filled with the signal state of the sign bit.
These four bits are lost.
1 1 1 1 0 0 0 0 1 0 1 0
1 1 1 1 1 0 1 0 1 1 1 1 0 0 0 0 1 0 1 0
Sign bit
长沙工控帮教育科技有限公司整理
Status word
BR CC 1 CC 0 OV OS OR STA RLO /FC
writes: x x x x - x x x 1
Example
SHR_I
N IN EN
MW0 MW4
Q 4.0 I 0.0
MW2
ENO OUT
S
The SHR_I box is activated by logic "1" at I0.0. MW0 is loaded and shifted right by the number of bits specified with MW2. The result is written to MW4. Q4.0 is set.
11.1.3 SHR_DI Shift Right Double Integer
Symbol
SHR_DI EN
OUT N
ENO IN
Parameter Data Type Memory Area Description
EN BOOL I, Q, M, L, D Enable input
ENO BOOL I, Q, M, L, D Enable output
IN DINT I, Q, M, L, D Value to shift
N WORD I, Q, M, L, D Number of bit positions to shift
OUT DINT I, Q, M, L, D Result of shift instruction
长沙工控帮教育科技有限公司整理
Description
SHR_DI (Shift Right Double Integer) is activated by a logic "1" at the Enable (EN) Input. The SHR_DI instruction is used to shift bits 0 to 31 of input IN bit by bit to the right. The input N specifies the number of bits by which to shift. If N is larger than 32, the command acts as if N were equal to 32. The bit positions shifted in from the left to fill vacated bit positions are assigned the logic state of bit 31 (sign bit for the double integer). This means these bit positions are assigned "0" if the integer is positive and "1" if the integer is negative. The result of the shift instruction can be scanned at output OUT. The CC 0 bit and the OV bit are set to "0" by SHR_DI if N is not equal to 0.
ENO has the same signal state as EN.
Status word
BR CC 1 CC 0 OV OS OR STA RLO /FC
writes: x x x x - x x x 1
Example
SHR_DI
N IN EN
MD0 MD10
Q 4.0 I 0.0
MW4
ENO OUT
S
The SHR_DI box is activated by logic "1" at I0.0. MD0 is loaded and shifted right by the number of bits specified with MW4. The result is written to MD10. Q4.0 is set.
长沙工控帮教育科技有限公司整理
11.1.4 SHL_W Shift Left Word
Parameter Data Type Memory Area Description
EN BOOL I, Q, M, L, D Enable input
ENO BOOL I, Q, M, L, D Enable output
IN WORD I, Q, M, L, D Value to shift
N WORD I, Q, M, L, D Number of bit positions to shift
OUT WORD I, Q, M, L, D Result of shift instruction
Description
SHL_W (Shift Left Word) is activated by a logic "1" at the Enable (EN) Input. The SHL_W instruction is used to shift bits 0 to 15 of input IN bit by bit to the left. Bits 16 to 31 are not affected. The input N specifies the number of bits by which to shift.
If N is larger than 16, the command writes a "0" at output OUT and sets the bits CC 0 and OV in the status word to "0". N zeros are also shifted in from the right to fill vacated bit positions. The result of the shift instruction can be scanned at output OUT. The CC 0 bit and the OV bit are set to "0" by SHL_W if N is not equal to 0.
ENO has the same signal state as EN.
IN
6 places N
OUT
The vacated places are filled with zeros.
These six bits are lost.
Status word
BR CC 1 CC 0 OV OS OR STA RLO /FC
writes: x x x x - x x x 1
Example
SHL_W
N IN EN
MW0 MW4
Q 4.0 I 0.0
MW2
ENO OUT
S
The SHL_W box is activated by logic "1" at I0.0. MW0 is loaded and shifted left by the number of bits specified with MW2. The result is written to MW4. Q4.0 is set.
11.1.5 SHR_W Shift Right Word
Symbol
SHR_W EN
OUT N
ENO IN
Parameter Data Type Memory Area Description
EN BOOL I, Q, M, L, D Enable input
ENO BOOL I, Q, M, L, D Enable output
IN WORD I, Q, M, L, D Value to shift
N WORD I, Q, M, L, D Number of bit positions to shift
OUT WORD I, Q, M, L, D Result word of shift instruction
长沙工控帮教育科技有限公司整理
Description
SHR_W (Shift Right Word) is activated by a logic "1" at the Enable (EN) Input. The SHR_W instruction is used to shift bits 0 to 15 of input IN bit by bit to the right. Bits 16 to 31 are not affected. The input N specifies the number of bits by which to shift.
If N is larger than 16, the command writes a "0" at output OUT and sets the bits CC 0 and OV in the status word to "0". N zeros are also shifted in from the left to fill vacated bit positions. The result of the shift instruction can be scanned at output OUT. The CC 0 bit and the OV bit are set to "0" by SHR_W if N is not equal to 0.
ENO has the same signal state as EN.
Status word
The SHR_W box is activated by logic "1" at I0.0. MW0 is loaded and shifted right by the number of bits specified with MW2. The result is written to MW4. Q4.0 is set.
11.1.6 SHL_DW Shift Left Double Word
Symbol
Parameter Data Type Memory Area Description
EN BOOL I, Q, M, L, D Enable input
ENO BOOL I, Q, M, L, D Enable output
IN DWORD I, Q, M, L, D Value to shift
N WORD I, Q, M, L, D Number of bit positions to shift
OUT DWORD I, Q, M, L, D Result double word of shift
instruction
长沙工控帮教育科技有限公司整理
Description
SHL_DW (Shift Left Double Word) is activated by a logic "1" at the Enable (EN) Input. The SHL_DW instruction is used to shift bits 0 to 31 of input IN bit by bit to the left. The input N specifies the number of bits by which to shift. If N is larger than 32, the command writes a "0" at output OUT and sets the bits CC 0 and OV in the status word to "0". N zeros are also shifted in from the right to fill vacated bit positions. The result double word of the shift instruction can be scanned at output OUT. The CC 0 bit and the OV bit are set to "0" by SHL_DW if N is not equal to 0.
ENO has the same signal state as EN.
Status word
BR CC 1 CC 0 OV OS OR STA RLO /FC
writes: x x x x - x x x 1
Example
SHL_DW
N IN EN
MD0 MD10
Q 4.0 I 0.0
MW4
ENO OUT
S
The SHL_DW box is activated by logic "1" at I0.0. MD0 is loaded and shifted left by the number of bits specified with MW4. The result is written to MD10. Q4.0 is set.
长沙工控帮教育科技有限公司整理
11.1.7 SHR_DW Shift Right Double Word
Parameter Data Type Memory Area Description
EN BOOL I, Q, M, L, D Enable input
ENO BOOL I, Q, M, L, D Enable output
IN DWORD I, Q, M, L, D Value to shift
N WORD I, Q, M, L, D Number of bit positions to shift
OUT DWORD I, Q, M, L, D Result double word of shift
instruction
Description
SHR_DW (Shift Right Double Word) is activated by a logic "1" at the Enable (EN) Input. The SHR_DW instruction is used to shift bits 0 to 31 of input IN bit by bit to the right. The input N specifies the number of bits by which to shift. If N is larger than 32, the command writes a "0" at output OUT and sets the bits CC 0 and OV in the status word to "0". N zeros are also shifted in from the left to fill vacated bit positions. The result double word of the shift instruction can be scanned at output OUT. The CC 0 bit and the OV bit are set to "0" by SHR_DW if N is not equal to 0.
ENO has the same signal state as EN.
1 1 1 1 1 1 1 1 0 1 0 1 0 1 0 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1
The vacated places are filled with zeros.
These three bits are lost.
长沙工控帮教育科技有限公司整理
Status word
BR CC 1 CC 0 OV OS OR STA RLO /FC
writes: x x x x - x x x 1
Example
SHR_DW
N IN EN
MD0 MD10
Q 4.0 I 0.0
MW4
ENO OUT
S
The SHR_DW box is activated by logic "1" at I0.0. MD0 is loaded and shifted right by the number of bits specified with MW4. The result is written to MD10. Q4.0 is set.
长沙工控帮教育科技有限公司整理