5.2.获取-执行循环
\(5.2.\)The Fetch-Execute Cycle
- Fetch an instruction from the program memory
- Execute it
1.Fetching
The next instruction is located at the program memory, the program memory is in the memory, and its address is specified by the program counter.
We need to basically put the location of the next instruction into the "address" of the program memory. Then we need to read the contents at that location and then will get the basic instructions we need to execute.
We usually put the address of the next instruction into the address input of the program memory by program counter.
The hardware cycle of executing the fetch operation is as below:
- When we need to jump into a new location, we manipulate the program counter so that it will have the address of the next instruction.
- The output of the program counter feeds into the address specification of program memory.
- The program memory output comes the actual instruction code that we need to execute.
2.Execute
The instruction code specifies "what to do"
- Which arithmetie or logical instruction.
- What memory to access (read/write).
- If/where to jump.
Bit aspect: Execute current instruction means taking the bits from the instruction code that specifies what to do, and do what needs to be done.
- Often, different subsets of the bits control different aspects of the operation
Hardware aspect:
control bus:
tells the ALU what instruction to compute,
tells where do the data pieces come from,
2.The clash
There's a clash in the cycle above:
- For fetch, we need to put into the address of the memory the address of the next instruction to get the instruction output.
- For execute, we need to put into the address of the memory the address of the data pieces that we want to operate on to access data.
- But we only have a single memory, so should we put into the memory the address of data or instructions?
To solve this problem, we will do one after another. We will achieve this through a Multiplexer:
- In the first part, the fetch cycle, the multiplexer set the memory to point into the program counter that is the location of the next instruction.
- While in the execute cycle, the multiplexer will set the memory to point into the data address that we need to access.
So how do we do this together?
- When we are in a fetch cycle, we get the next instruction, and then we need to remember it inside an instruction register.
- That instruction register is exactly what is remains holding the value of the instruction that we are now executing in the execute cycle. Then in the execute cycle we have the instruction already stored in this register, so we can work with all the information we need for the cycle.