The difference between shift instruction and circular shift instruction S7-1200 shift instruction flow light control programming

Publisher:平静心境Latest update time:2024-07-16 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The difference between shift instructions and rotate instructions

Shift instructions and circular shift instructions are common operation instructions in computer architecture, which are used to perform bit-level movement operations on binary data. The difference between them lies in the way the shifted data is processed during the shift.


The shift instruction shifts the data in the specified direction. The shifted bits are discarded and the shifted bits are filled with 0. There are two forms of shift operations: left shift and right shift. Left shift will multiply the value by a power of 2, while right shift will do the opposite.

In addition to performing the functions of ordinary shift instructions, the rotate instruction also has the feature of looping to process the shifted bits. In a rotate shift, the shifted bits are not lost, but are re-circulated to the other end. The rotate shift instruction is implemented by specifying the rotation direction (left or right) and the number of bits to be rotated. When the shift operation is completed, the shifted bits are reinserted to the other end instead of being discarded.

Circular shift instructions are often used in bit operations, cryptography, graphics processing and other fields to achieve functions such as circular displacement and circular loopholes. In contrast, ordinary shift instructions are more suitable for simple bit operations.

Effect of shift instructions on flag bits

Shift instructions usually set or update some flag bits, which are used to record some status information during the shift operation . The specific effect depends on the specific computer architecture and instruction set.

Common flags include:

1. Carry Flag: Records whether the shift operation results in data overflow or carry. When shifting right, the carry flag is set to the rightmost bit that is discarded. When shifting left, the carry flag is set to the leftmost bit that is shifted in.

2. Zero Flag: Indicates whether the result after the shift operation is zero. When the shift operation results in all zeros, the zero flag is set to 1; otherwise, it is set to 0.

3. Overflow Flag: Used to record whether the shift operation causes a signed number overflow. The behavior of this flag may vary in different architectures.

4. Sign Flag: records the most significant bit of the shift result (i.e., the sign bit). If the most significant bit of the result is 1, the sign flag is set to 1; if the most significant bit of the result is 0, it is set to 0.

Different computer architectures may have different flag bit settings and naming. Therefore, the specific impact will depend on the architecture and instruction set used. When using shift instructions, you can consult the relevant documentation or refer to the instruction set manual to understand the specific flag bit operations.

Which flag bits are affected by the shift instructions?

Shift instructions typically set or update the following flags:

1. Carry Flag: In a right shift operation, the carry flag is set to the lowest bit that is discarded; in a left shift operation, the carry flag is set to the highest bit (sign bit).

2. Zero Flag: If the result of the shift operation is zero, the zero flag is set to 1, otherwise it is set to 0.

3. Overflow Flag: In some architectures, shift instructions may affect the overflow flag, but this is not a feature of all architectures. Therefore, in a specific architecture, you need to refer to the relevant documentation or instruction set manual to determine the impact of shift instructions on the overflow flag.

4. Sign Flag: In a left shift operation, the sign flag is set to the highest bit (sign bit) of the shift result. If the highest bit is 1, the sign flag is set to 1; if the highest bit is 0, it is set to 0.

The specific impact will vary depending on the computer architecture and instruction set. Therefore, in practical applications, the impact of shift instructions on flag bits should be determined based on the architecture and instruction set used.

S7-1200 PLC circular shift instruction for flow light control

The circular shift instruction (CIRC) can be used to implement the running light control. The following is a basic example, using S7-1200 PLC to control the running light effect of 8 LED lights.

1. Milling, perform hardware configuration in PLC , and connect 8 LED lights to 8 output ports of PLC.

2. Create a new S7-1200 project in the TI A Portal and create a program block.

3. Define an 8-bit variable By te 1 in the program block to represent the status of the 8 LED lights.

4. Use loop query in the main program to loop and perform the following operations:

(1) Shift the Byte1 variable left by one bit and store the value of the highest bit in the lowest bit.

(2) Output the Byte1 variable to the 8 output ports of the PLC to control the on and off of the ED light.

(3) Delay for a period of time to control the speed of the running lights.

5. Compile the program and upload it to the PLC for execution.

The following is a simple S7-1200 PLC program example to achieve the effect of 8 LED lights:

wKgZomTA1LqARenIAACTjVr1Xp8617.png

In the above program, the CIRC instruction shifts the Byte1 variable left by - - bits and stores the value of the highest bit in the lowest bit. For example, if the value of Byte1 is 0000001 (= - hexadecimal), executing

After the CIRC instruction, the value of Byte 1 becomes 0000010 (binary).

The BOOL_ _TO_ _BYTE and BYTE_ TO_ _BOOL functions can convert between BOOL and BYTE types. For example, BYTE_ TO_ _BOOL (Byte1.0) converts the Byte1 variable to

The lowest bit is converted to BOOL type and output to the Q0.0 output port.

Finally, use the TON_ Delay instruction to delay for a period of time to control the speed of the running light. For example, setting the PT parameter to T#1S means a delay of 1 second.


Reference address:The difference between shift instruction and circular shift instruction S7-1200 shift instruction flow light control programming

Previous article:What are neural networks? Why are they important? How do neural networks work?
Next article:A brief introduction to motor controllers

Recommended ReadingLatest update time:2024-11-16 10:52

A Brief Analysis of Siemens S7-1200 Serial Communication Technology
This type of PtP communication is serial communication that uses a standard UART to support multiple baud rate and parity options. The RS232 and RS422/485 Communication Module (CM1241) and RS485 Communication Board (CB 1241) provide the electrical interface for performing PtP communication.
[Embedded]
A Brief Analysis of Siemens S7-1200 Serial Communication Technology
Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号