teach-ict.com logo

THE education site for computer science and ICT

3. Fetch

CPUs process program instructions one at a time. Whenever it is ready to process a new instruction, that instruction has to be fetched from main memory. This is the first step in the 'Fetch-Execute' cycle.

Instructions are transferred from main memory to the CPU via the data bus.

The CPU stores the instruction it is processing in a register called the Memory Buffer Register (MBR).

Program counter

The CPU needs to keep track of where in memory the current instruction came from. This location is called the 'memory address' of the instruction.

This is the job of the program counter. The program counter is a register (a very fast type of memory) within the CPU. The control unit uses the program counter to keep track of the 'memory address' of the current instruction.

Instructions within programs are contiguous, which means that they are stored in memory one after the other. So when the contol unit is done processing an instruction, it can find the address of the next one by incrementing the program counter. Not always though, the current instruction may be telling it to jump to another part of the program, in which case the program counter is loaded with the memory address of the new instruction.

Fetching an instruction takes 1 tick of the CPU clock.

Summary:

  • The program counter stores the memory address of the current instruction.
  • Once an instruction is processed, the control unit increments the program counter to point to the next instruction. If the current instruction was a 'jump' command, then the program counter is adjusted to point to the new instruction.
  • The control unit fetches the next instruction from main memory
  • It knows the address of the instruction because of the program counter.
  • The instruction is fetched into the MBR via the data bus.

 

Challenge see if you can find out one extra fact on this topic that we haven't already told you Click on this link: Fetch Decode Cycle