Home  >  Article  >  The execution process of an instruction in the CPU

The execution process of an instruction in the CPU

hzc
hzcOriginal
2020-06-12 11:54:1912243browse

The execution process of an instruction in the CPUThe execution process of an instruction in the CPU:

The work of almost all von Neumann type computer CPUs can be divided into 5 parts Stages: fetch instructions, decode instructions, execute instructions, access data, and write back results.

1. Instruction Fetch Phase

The Instruction Fetch (IF) phase is the process of fetching an instruction from main memory to the instruction register.

The value in the program counter PC is used to indicate the location of the current instruction in main memory. When an instruction is fetched, the value in PC will be automatically incremented according to the instruction word length: if it is a single-word-length instruction, then (PC) 1àPC; if it is a double-word-length instruction, then (PC) 2àPC, and so on.

2. Instruction Decoding Phase

After fetching the instruction, the computer immediately enters the Instruction Decode (ID) phase.

In the instruction decoding stage, the instruction decoder splits and interprets the retrieved instructions according to the predetermined instruction format, and identifies and distinguishes different instruction categories and various methods of obtaining operands.

In computers controlled by combinational logic, the instruction decoder generates different control potentials for different instruction opcodes to form different micro-operation sequences; in computers controlled by microprograms, the instruction decoder uses The instruction opcode is used to find the entry point of the microprogram that executes the instruction, and execution starts from this entry point.

3. Execution instruction phase

After the instruction fetching and instruction decoding stages, the execution instruction (Execute, EX) stage is entered.

The task at this stage is to complete various operations specified by the instruction and specifically implement the function of the instruction. For this purpose, different parts of the CPU are connected to perform the required operations.

4. Access and access phase

According to the instruction requirements, it may be necessary to access the main memory and read the operand, thus entering the access and access (Memory, MEM) phase.

The task of this stage is: according to the instruction address code, obtain the address of the operand in the main memory, and read the operand from the main memory for operation.

5. Result write back stage

As the last stage, the result write back (Write Back, WB) stage "writes back" the running result data of the execution instruction stage to some storage form:

The result data is often written to the CPU's internal registers so that it can be quickly accessed by subsequent instructions;

In some cases, the result data can also be written relatively slowly, but cheaper and Main memory with larger capacity. Many instructions also change the status of the flag bits in the program status word register. These flag bits identify the results of different operations and can be used to affect the actions of the program.

After the instruction is executed and the result data is written back, if no unexpected events (such as result overflow, etc.) occur, the computer will then obtain the next instruction address from the program counter PC and start a new cycle. The next instruction cycle will fetch the next instruction sequentially.

The above is the detailed content of The execution process of an instruction in the CPU. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn