Back

The function of the CPU in fetching and executing instructions

Introduction

FDEWe saw in the last section that the purpose of a CPU is to fetch instructions, decode them and then execute them. This is often referred to as the FETCH - DECODE - EXECUTE cycle, or sometimes just the FETCH - EXECUTE cycle. But where does it fetch instructions from?

The role of RAM in the Fetch - Decode - Execute cycle
You may have many different programs on your computer. These are usually stored on your hard drive, whether they are being used at any moment in time or not. When you start a program, usually by double-clicking on its icon on the desktop, a copy of the program is moved into the computer's main memory, otherwise know as RAM (Random Access Memory). The CPU then fetches instructions, one at a time, from this main memory.

Interestingly, the CPU can only fetch, decode and execute one instruction at a time! However, it can do this very quickly indeed.

Primary memory (Immediate Access Storage, IAS) versus secondary storage and the FDE cycle
It is worth noting that the CPU can't fetch instructions for programs stored on the hard drive. it can only get instructions from the main memory. For this reason, the main memory, apart from being called RAM is also known as primary memory as well as immediate access storage whilst the hard drive is an example of a secondary storage device. (Just to confuse things even further, you will often see the words memory and storage used interchangeably in computing; one book or web site you are reading will say 'primary memory' and 'secondary memory' and another will say 'primary storage' and 'secondary storage'!)

In fact, all storage devices are usually referred to as secondary storage devices, whether it is a CD, a DVD, a pen drive, an SD card and so on. It is unfortunate that some things like RAM have so many different names used for them but we have to get used to start learning them and the best way of doing that is to use them.

So, the reason CDs, hard drives, pen drives and so on are 'secondary' and not 'primary' storage or memory is simply because the CPU cannot access them directly; any programs the CPU wants to run have to be copied into RAM first. Only then can the CPU carry out the Fetch - Decode - Execute cycle.

Back