PC 2: Program Process Control

Source: Internet
Author: User

After we understood that the only purpose of using computers was to process data, we began to pave the way for data. We designed a bus to connect various devices to the bus, and then designed rules similar to "traffic lights" to control the data flow at the same time without confusion, at the same time, we began to address the data storage space on the bus, so that the CPU device can exchange data with these address spaces.

What's more powerful is that we have designed commands to control the data interaction between the CPU and other devices, as well as the internal arithmetic and logical operations of the CPU. In this way, the combination of computer commands can basically complete all the functions.

However, how can the CPU execute these computer commands in sequence? They cleverly designed the instruction pointer register. The instruction pointer register points to the address of the next instruction to be executed in the memory. Each time an instruction is executed, the instruction pointer Register automatically points to the next instruction. In this way, the CPU can work mechanically. The hidden problem here is that the command length is different. Some commands have no operands, but may be 1 byte. Some commands may carry an operand, but more than one byte. This should be treated differently. However, this is also a clever implementation, that is, the number of bytes read by the previous command, so the next command will offset the number of bytes to the back, so there will be no error.

Is that all right? Not yet. We also need branch and loop control. This is used to help programmers write more elegant code, rather than writing 100 commands from 1 to 100. In addition, in order to increase the adaptability of the program, the program does not know what scenarios the program will face in the future. In the program, different code needs to be executed according to different background requirements, this requires branch.

Branches and loops are implemented through jump commands. Generally, the CPU provides conditional jump and unconditional jump commands. Branch and loop control is implemented through conditional jump. The so-called conditional jump is to add the Status Register to the CPU, set the annotation bit in this register, there is a jump address in the conditional jump command, when executing the command, first judge the flag. If yes, the system jumps. If not, do nothing. Execute the next command. When the program needs to jump, we first execute the "judgment" command that will affect the flag bit, and then execute the conditional jump to achieve our needs. This only needs to be considered in assembly languages. In advanced languages, the underlying implementation principle has been shielded by natural languages.

With these process control commands, the CPU can basically complete various business needs under the control of program commands, and programmers can also write programs to allow computers to complete various tasks, this is a great creation. This makes computer hardware more and more common, and computer software more and more powerful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.