CS255 Syllabus
Instruction execution cycle
- From the very moment that you turn on a computer until
you turn it off, the CPU performs the following sequence of steps
ad infinitum.
(The cycle is known as the "Instruction Execution Cycle")
- Instruction Execution Cycle:
- Fetch the instruction from main memory from
the memory location given by the program counter (PC) into
the instruction register IR.
Increment the PC to make it point to the following instruction.
- the CPU sends PC in the MAR and sends a READ command
on the control bus
- in response to the read command (with address equal to PC),
the memory returns the data stored at the memory location
indicated by PC on the databus.
- the CPU copies the data from the databus into its MBR
- a fraction of a second later, the CPU copies the data from the MBR
to the Instruction Register (IR)
- The PC is incremented so that it points to the following instruction
in memory. This step prepares the CPU for the next cycle.
- This completes the instruction fetch step...
- Decode the instruction just fetched in the IR
- This process can be very simple or complex, depending on
the instruction encoding scheme used.
- Instruction encoding using fixed length instruction formats
(like SPARC, MIPS) is usually very regular and decoding will
be easy.
- Variable length instruction formats usually have more
complex decoding schemes.
- The decoding process allows the CPU to determine what instruction
is to be performed, so that the CPU can tell how many
operands it needs to fetch in order to perform the instruction.
- Fetch operands needed to execute the instruction
- Operands can reside inside the general purpose registers
of the CPU and in memory
- Execute the instruction
- The operation is carried out and the result is (typically) stored
(written) in one of the general purpose registers or memory
- The CPU will update the result flags (N, Z, V, C) according to
the result of the operation.
- After this step, the CPU repeat the cycle from the start.
Notice now that the program counter (PC) points to
another instruction !
- Example: PC points to the instruction X in memory and
instruction X is "Add integer in address 1000 to integer in
address 2000 and store sum at address 3000"
- Fetch: Instruction "X" is fetched from memory into IR of the CPU
- Decode: Instruction "X" is decoded and CPU determines that
it needs data from memory locations 1000 and 2000.
- Fecth Operands: CPU fetches integers from memory 1000 and 2000
- Execute: CPU adds the integers and store sum in address 3000.
CPU updates the flags N,Z,V,C according to the result
of the sum.