Machine Level Architecture: The Fetch–Execute cycle and the role of registers within it

From Wikibooks, open books for an open world
Jump to: navigation, search

UNIT 2 - ⇑ Machine Level Architecture ⇑

← Machine code and processor instruction set The Fetch–Execute cycle and the role of registers within it

The Fetch-Decode-Execute cycle of a computer is the process by which a computer:

  1. fetches a program instruction from its memory,
  2. determines what instruction wants to do,
  3. and carries out those actions.

This cycle is repeated continuously by the central processing unit (CPU), from bootup to when the computer is shut down. In modern computers this means completing the cycle billions of times a second! Without it nothing would be able to be calculated.

Registers involved[edit]

The circuits used in the CPU during the cycle are:

  • Program Counter (PC) - an incrementing counter that keeps track of the memory address of which instruction is to be executed next...
  • Memory Address Register (MAR) - the address in main memory that is currently being read or written
  • Memory Buffer Register (MBR) - a two-way register that holds data fetched from memory (and ready for the CPU to process) or data waiting to be stored in memory
  • Current Instruction register (CIR) - a temporary holding ground for the instruction that has just been fetched from memory
  • Control Unit (CU) - decodes the program instruction in the CIR, selecting machine resources such as a data source register and a particular arithmetic operation, and coordinates activation of those resources
  • Arithmetic logic unit (ALU) - performs mathematical and logical operations

Register notation[edit]

To describe the cycle we can use register notation. This is a very simple way of noting all the steps involved. In all cases where you see brackets e.g. [PC], this means that the contents of the thing inside the brackets is loaded. In the case of the first line, the contents of the program counter is loaded into the Memory Address Register.

MAR\gets [PC]
MBR\gets [Memory]_{MAR  address}; PC\gets [PC]+1 (Increment the PC for next cycle at the same time)
CIR\gets [MBR]
[CIR] decoded then executed

Detailed description of Fetch-Decode-Execute Cycle[edit]

To better understand what is going on at each stage we'll now look at a detailed description:

CPT-fetch-execute-MAR-PC.svg

The contents of the Program Counter, the address of the next instruction to be executed, is placed into the Memory Address Register

CPT-fetch-execute-MBR-Memory.svg

The address is sent from the MAR along the address bus to the Main Memory. The instruction at that address is found and returned along the data bus to the Memory Buffer Register. At the same time the contents of the Program Counter is increased by 1, to reference the next instruction to be executed.

CPT-fetch-execute-CIR-MBR.svg

The MBR loads the Current Instruction Register with the instruction to be executed.

CPT-fetch-execute-CIR-executes.svg

The instruction is decoded and executed using the ALU if necessary.

The Cycle starts again!

Exercise: Fetch Execute Cycle

Name 3 registers involved in the Fetch Execute Cycle and describe what each does:

Answer :

  • Program Counter (PC) - an incrementing counter that keeps track of the memory address of which instruction is to be executed next...
  • Memory Address Register (MAR) - holds the address in memory of the next instruction to be executed
  • Memory Buffer Register (MBR) - a two-way register that holds data fetched from memory (and ready for the CPU to process) or data waiting to be stored in memory
  • Current Instruction register (CIR) - a temporary holding ground for the instruction that has just been fetched from memory

Describe the Fetch Execute Cycle using register notation:

Answer :

MAR\gets [PC]
MBR\gets [Memory]_{MAR  address}; PC\gets [PC]+1
CIR\gets [MBR]
CIR executes

Complete the following diagrams showing each step of the fetch decode execute cycle:

CPT-fetch-execute-MAR-PC-ex1.svg

Answer :

CPT-fetch-execute-MAR-PC-ans1.svg

CPT-fetch-execute-MBR-Memory-ex1.svg

Answer :

CPT-fetch-execute-MBR-Memory-ans1.svg

CPT-fetch-execute-CIR-MBR-ex1.svg

Answer :

CPT-fetch-execute-CIR-MBR-ans1.svg

CPT-fetch-execute-CIR-executes-ex1.svg

Answer :

CPT-fetch-execute-CIR-executes-ans1.svg