- The instruction fetch step:
- In this step, the CPU will
fetch the
instruction
from the
memory that is
stored at the memory address given by
the value inside the
Program Counter (PC) into
the Instruction Register of the
CPU
Recall that the
Program Counter (special register)
contains the
address (= location in memory) of
the next instruction.
So in this step, the CPU will
fetch a copy the next instruction
from the memory into
its Instruction register.
After fetching the instruction from memory, the
CPU will
update (= increase) the
Program Counter so it will
contain the
address of the
subsequent instruction.
When this step is completed:
- The Instruction Register inside the
CPU will contain the next instruction that the CPU must execute
- The CPU prepared itself to
fetch a new next instruction
(= which is the instruction that
physically follows the
fetched instruction)
So this preparation will ingeniously enable the
repetition of
the same steps to fetch
(and execute) a
different instruction !
|
The remaining 3 steps of the Instruction Execution Cycle are
responsible to execute this instruction.
|
- The instruction decode step
- The instruction is
represented by a
binary pattern
(because the computer memory can only store binary patterns)
- Each binary pattern will
represent a certain
computer operation
- Before the CPU
can perform an instruction,
the CPU must find out what is
the instruction that is
represented (= encoded) by the
binary pattern
- The CPU contains circuitry to
decode the
instruction's binary pattern - you will learn more about these
circuits in CS 355
- For CS255, you only need to know
that
in the instruction decode step,
the CPU will find out:
- What operation the CPU needs to
perform (e.g.: add, subtract, multiply, divide, negate,
logical AND, logical OR, logical NOT, etc.)
- Which operands the CPU needs to
use in the operation and
where to store the
result
(e.g.: if the instruction was "add", then which
input values should "add" use, and where
to store the sum)
|
|
- The operand fetch step
- The instruction executing step
- In this final step, the
CPU will
perform the operation specified by
the instruction code on the
fetched operands
- After performing the
operation, the
result of the
operation will
be saved in the
designated register
|
After the instruction execution step,
the operation specified in the
instruction
(that was fetched in step 1 of the
Instruction Execution Cycle) is
complete !!
The
CPU can
discard the
instruction in the
Instruction Register
(You don't need to keep the instruction or save it back in memory, because
the instruction in the Instruction Register is
a copy transfered from memory.
So just like you can discard an
meal order at
McDonalds or some
restaurant
after fulfilling the order,
the CPU can
discard the
instruction after executing (= "fulfilling") the operation !)
Notice that:
The CPU can now
repeat the
Instruction Execution Cycle
again !!!
When the CPU repeats the Instruction Execution Cycle,
it will fecth a
different instruction
(because the CPU has made the necessary preparation in
Step 1 !!!)
|