Architecture of the CPU

Basic computer system model

A computer system is made up of hardware and software. Hardware is any physical component that makes up a computer. Software is any program that runs on a computer.

Computer systems are all around us. They are not just the PCs on a desk but include mobile phones, cash machines, supermarket tills and the engine management systems in a modern-day car.

The diagram below shows the basic model of a computer system.

[Memory]

↑↓

[Input] → [CPU (processor)] → [Output]

↑↓

[Secondary storage]

All computer systems must have a central processing unit (CPU), also called simply the processor, and at least one input device that gets data from the real world. This could be a mouse and keyboard on a conventional PC, a temperature sensor (thermistor) in a commercial greenhouse or the microphone on a mobile phone.

Input devices take real world data and convert it into a form that can be stored on the computer. The input from these devices is processed and the computer system will generate outputs. The output device could be, for example, a conventional computer screen, an actuator that opens or closes a greenhouse window, or the speaker that produces sound on a phone.

The computer must have memory (primary storage), used for holding instructions currently being executed and data that is being used.

Any computer system will have these four basic components.

The fifth component is secondary storage. The computer system may need to use stored data to perform the processing and, as a result of processing input, may generate data that is then stored. Storage devices such as hard disks can hold large amounts of data including databases, text documents, programs, music files and photographs.

Q1: Name three input, output and storage devices.

Common CPU components and their function

The Central Processing Unit (CPU) of a computer is the hardware that executes programs and manages the rest of the hardware. Think of the CPU as the brain of the computer. Just as your brain contains parts that remember things, parts that think and parts that make the rest of your body operate, the CPU does the same for the computer. The computer also contains main memory and cache memory. Cache (pronounced "cash") is very fast memory, close to the CPU, used to temporarily hold data or instructions that are likely to be needed again by the processor in the course of running a program.

Control Unit

The Control Unit coordinates all the activities taking place inside the CPU. Its functions may be summarised as follows:

  • It controls the execution of instructions in the correct sequence
  • It decodes instructions
  • It regulates and controls processor timing using regular pulses from the system clock
  • It sends and receives control signals to and from other devices within the computer

The Arithmetic and Logic Unit (ALU)

The ALU carries out the following functions:

  • Logical Operations: These include AND, OR and NOT.
  • Shift Operations: The bits in a computer word can be shifted left or right by a certain number of places.
  • Arithmetic Operations: These include addition, subtraction, multiplication and division.

Von Neumann architecture

With the very first computers, it was not possible to store programs, and programs were generally input by setting switches. John Von Neumann developed the concept of the stored program computer in the 1940s. The Von Neumann architecture used the idea of holding both programs and data in memory. Data would then move between the memory unit and the processor.

[Storage]
↑↓
[Input devices] → [Processor (CPU)] → [Output devices]
↑↓
[Cache]
↑↓
[Main Memory]

Fetch-Decode-Execute cycle

When a program is to be run (executed) on a computer it first has to be loaded into main memory. From here it can be accessed by the processor, which runs each instruction in turn. When the program is loaded, the processor is given the start address of where it is held in main memory.

[Fetch an instruction from main memory] → [Decode the instruction] → [Execute the instruction] → (Loop back)

To run the program the processor fetches an instruction, decodes it and then executes it. The processor executes one instruction at a time. This is called the Fetch-Decode-Execute cycle, or simply the Fetch-Execute cycle.

The processor contains the Control Unit (CU), the Arithmetic Logic Unit (ALU) and registers.

Special-purpose registers

A register is a special very fast memory location within the CPU used in the execution of instructions.

A CPU has number of special-purpose registers, listed below:

  • The Memory Address Register (MAR) holds the address (location in memory) of the instruction or piece of data to be fetched or stored.
  • The Memory Data Register (MDR) holds data or a program instruction temporarily when it is fetched from memory or is to be sent to memory.
  • The Program Counter (PC) holds the memory address of the next instruction to be processed.
  • The Accumulator (ACC) is a special-purpose, memory location in which results of operations carried out in the ALU are temporarily stored. (N.B. Most processors have several general-purpose registers, instead of a single accumulator, which are used as temporary fast storage.)

For example, the assembly code below fetches a value from main memory, adds 80 to it and stores the result of the addition back into memory. Each location in memory has its own unique address.

LDA 2560     loads the data at address 2560 into the accumulator (ACC)
ADD #80      adds the value 80 to the present content of the accumulator
STA 2560     stores the content of the accumulator in memory location 2560

In order to execute the first instruction, LDA 2560, the address, the address 2560 is passed to the Memory Address Register (MAR) and the computer transfers the data from this memory location to the Memory Data Register (MDR). From here the data is passed to the accumulator to be used in the calculation.

When you write an instruction in Python or Visual Basic, for example:

a = a + 80

it is broken down into these three basic instructions.

CPU performance

Clock speed

The main factors affecting CPU performance are:

  • Clock speed
  • Cache size
  • Number of cores

Each of these is described below.

The speed at which a processor operates is quoted as the clock speed, and measured in hertz. Hertz is the name for the number of cycles per second, or the rate at which the electrical current changes in the actual circuits. Everything the processor does occurs on the 'tick' of the clock - so a faster clock means that more instructions are fetched, decoded and executed in a second.

One clock cycle per second = 1 hertz (Hz), and clock speed is measured in Gigahertz (GHz), one billion cycles per second. Typical speeds for a PC are between 2GHz and 4GHz. The greater the clock speed, the faster instructions will be executed.

In theory a computer with a 4GHz processor should operate twice as fast as one with a 2GHz processor, but it isn't that simple. There are many other components that contribute to the overall speed of the computer. Each one can create a bottleneck in the system and slow it down.

Imagine a three-lane motorway where the traffic can go really fast until it gets to a single-lane road going into a town. No matter how many lanes you add to a motorway, the single-lane part of the journey will limit how quickly traffic can get into town. In the same way, a slow component can slow the whole computer down.

Number of cores

When we looked at the basic Fetch-Decode-Execute cycle we assumed that there was a single processor and a single main memory. You have probably heard the terms dual-core and quad-core, so where do these fit in?

Today's more complex CPUs typically include more than one core. A dual-core processor has two processing units within the CPU and a quad-core has four. This means that parallel processing can take place, with two or four instructions being executed simultaneously. In theory having two cores means that the computer can perform twice as many operations per second but this isn't always the case.

A program is a series of instructions that need to be done in order. Multiple cores could work on different programs that operate in parallel but unless the computer is designed to use multiple cores, a quad-core processor isn't necessarily four times faster. However, a PC with a multi-core processor, executing many tasks at the same time, will operate faster than a single-core processor.

CPU resources in a typical PC:

Base speed:3.20 GHz
Sockets:1
Cores:4
Logical processors:8
Virtualization:Enabled
L1 cache:384 KB
L2 cache:2.0 MB
L3 cache:8.0 MB

Cache memory

One bottleneck that can occur is the access speed of main memory, known as Random Access Memory (RAM). Reading from and writing to main memory is much slower than the speed at which the processor can work. The logical answer is to use faster memory technologies, but this increases the price of the computer.

Modern computers need to run many programs at the same time, so they need lots of memory. There needs to be a compromise between speed and cost.

One way of improving speed at minimal cost is to use a small amount of cache, much faster (but more costly) memory where frequently used instructions or data can be stored temporarily.

Cache memory is an intermediary between main memory and the CPU. The cache makes any data frequently used by CPU available much more quickly. Because the processor has to access main memory less often, it can work faster, so the CPU performance increases. If the required information is not located in the cache, it has to be fetched from RAM.

A typical PC (in 2020) might have 8 or 16GB of RAM (main memory) but only 2MB of the faster more expensive cache memory. Notice the different units here and remember that there are 1000 megabytes in a gigabyte. This computer therefore has thousands of times more RAM than cache memory.

The more cache memory a computer has, the more data and instructions can be held in cache and made available very quickly. This improves processor performance.

There are different 'levels' of cache:

  • Level 1 cache is extremely fast but small (between 2-64KB). Thus speeding up the Fetch-Execute cycle.
  • Level 2 cache is fairly fast (still much faster than RAM) and medium-sized (256KB-2MB).
  • Some CPUs also have Level 3 data cache.

Q2: Explain how clock speed and cache memory can affect the performance of a computer.

Q3: Which type of memory is the most expensive?

Embedded systems

An embedded system is a small computer built into a piece of equipment designed to perform a specific function. Examples of items that use this technology include: vehicles, cameras, medical equipment, aircraft, vending machines, ovens, fridges, mobile phones, satellite navigation devices, televisions, digital clocks and lifts.

Characteristics of an embedded system

The main characteristics of an embedded system are reliability and minimal resources such as ROM, timers, sensors and actuators.

The program which controls the equipment is held in ROM and cannot be changed. It is typically written in a machine-efficient language so that it uses the minimum amount of memory and executes as fast as possible. Assembly language may be used for some critical parts of the program.

It has a very limited operating system. Unlike the operating system in a desktop computer, the embedded operating system does not have to be loaded when the machine is switched on, as it is held in ROM. The operating system is only able to run a single application.

It has a very simple user interface, such as the buttons on a microwave oven or washing machine. Some embedded systems have no user interface.

Some embedded systems have sensors designed to measure external stimuli and react accordingly. For example, a central heating system may use buttons and sliders to make the heating come on at certain times of day, on different days, and maintain a chosen temperature.

Memory

Memory basics

Memory and storage devices can be split up into two distinct groups:

  • primary storage (memory)
  • secondary storage

Off-line storage refers to storage devices which can be stored away from the computer. Secondary storage devices are typically an integral part of the computer.

Q4: Name an off-line storage device that is read-only, i.e. cannot be written to.

Random Access Memory (RAM)

RAM is the type of memory used as the computer's main memory. Many people say "RAM" when they mean main memory. Nothing in a computer is really 'random' so random access just refers to the fact that data may be written anywhere in that memory space at any time. Memory space may become available anywhere in RAM as files are deleted. This space can be reused.

The need for primary storage

When a program is to be executed, it has to be loaded from the hard disk into main memory so that the processor can access the instructions. Any data needed for that program to run is also loaded into main memory. The main purpose of RAM is to act as temporary storage for programs and data while the program is being executed.

So why doesn't the processor get the instructions straight from the hard disk? It is about access speed. Reading from and writing to a hard disk is very slow compared to the speed of the processor. Just as we used the high speed cache between the processor and main memory, we need main memory to store the programs currently being executed or the computer would be really slow.

Access speed gets slower


Processor

Cache

Main Memory / RAM

Virtual Memory (on Hard Disk)

Virtual Memory

Sometimes there just isn't enough main memory to store the whole of a large program, or all the programs which are running at the same time (multi-tasking). Computers can be configured so that part of the hard disk drive (HDD) or solid state drive (SSD) behaves like main memory. This is called virtual memory. The access speed on an HDD or SSD is usually slower than the speed of RAM, so this isn't ideal. It is used to store parts of programs currently being run but the parts actually being executed still need to be in main memory. As the processor gets to the next part of the program, sections are swapped between virtual memory and main memory. Sometimes this works well but sometimes the computer spends more time swapping data than it does executing the program.

Q5: If this is happening a lot on your computer, what would be the cheapest way to upgrade it?

Volatility

If you are in the middle of a piece of work and you turn off your computer, you will lose the work you did since you last saved. This is because the saved version goes onto the HDD or SSD, but the most recent version was only in RAM when the power went off. HDD and SSD are designed for long term storage of files and are non-volatile memory.

RAM is volatile so when you turn off your computer it loses its contents. When you turn the computer back on it needs to get the basic startup routine from somewhere that is not volatile. The operating system and all your programs will be stored on the HDD/SSD but these need to be loaded into RAM to run.

The computer has a piece of software called the bootstrap loader. This is a small program that loads the operating system. Once the operating system is loaded it takes care of the rest. The term comes from the saying "pull yourself up by your bootstraps", which means to succeed or elevate yourself without outside help. Bootstrapping became abbreviated to booting, a term you have probably heard before. To 'boot' a computer is to start it up from scratch.

Read Only Memory (ROM)

ROM is Read Only Memory; you cannot write over the contents once it has been created. It is also non-volatile; you can leave the computer switched off for months and it will still start up as soon as it has power again. RAM on the other hand is only used for temporary storage of programs when they are running. RAM is read-write and volatile.

Key characteristics of RAM and ROM

RAM ROM
Volatile – data is lost when the power is turned off (temporary memory) Non-volatile – data is NOT lost when power is turned off (permanent memory)
Stores user data/programs/part of operating system which is currently in use Used to store the BIOS/bootstrap loader which is required at start-up of the computer
Memory can be written to or read from Memory can only be read from and NOT written to

We all want to store files for a long period of time. We keep photographs, projects, music, films, letters and spreadsheets on our computers. We also expect our programs to be there when we switch the computer on. This long-term storage is usually called secondary storage (primary storage is the main memory). Secondary storage refers to hard disk drives (HDDs), solid state drives (SSDs) and other devices and media such as Blu-ray discs.

Secondary storage

Secondary storage basics

Secondary storage is non-volatile, generally holds much more data than main memory and is relatively inexpensive per MB. However, secondary storage technologies tend to have slower access speeds than main memory.

Secondary storage needs to be robust and reliable. Has your memory stick been through the washing machine yet?

Choosing the right type of storage medium for a particular use is important. You need to consider the following features:

  • Capacity: How much space there is to store files. A memory stick holding 16GB costs under £3 – how many high-resolution photos each of 10MB can you store on it?
  • Speed: How quickly can the computer read data from a storage device or write data to it?
  • Portability: Can you easily unplug it and carry it away? Does it fit in a pencil case or do you need a large bag?
  • Durability: How easily is it damaged? Will it survive dropping or having coffee tipped on it?
  • Reliability: How long will it last? Anything with moving parts is likely to be less reliable.
  • Cost: Storage devices vary in cost per GB.

Magnetic devices

Magnetic disks are read with a moving head inside the disk drive. Moving parts make these media relatively slow to read from or write to and also make the disk more susceptible to damage. This is in contrast to solid state media (SSD) which have no moving parts. Magnetic media are also vulnerable to magnetic fields.

Magnetic disk drives can be either internal or portable (connected to the computer using a USB port).

Although hard disks are less portable than optical or solid state media, their huge capacity makes them very suitable for desktop purposes. Smaller, denser surface areas spinning under the read-write heads mean that newer disks have capacities of several terabytes.

The following table compares both types of hard disk drive:

Internal Hard Disk Portable Hard Disk
Physical size 3.5 Inches 2.5 Inches
Cost 8TB for £120
Capacity Up to 15TB 1TB to 16TB
Data transfer speed 100-200MB per second 100-200MB per second
Portability Not portable, built into PC Can fit in a large pocket
Durability Good durability when disk not in use but vulnerable to movement when spinning. Can write to the disk an infinite number of times. Affected by heat and magnetic fields
Reliability Extremely reliable
Typical use Inside a PC as secondary storage Supplementary storage for a PC or portable storage where high capacity is required

NOTE: portable hard disk drives are often referred to as off-line storage devices.

Solid State Drives

Solid State Drives (SSD) have no moving parts and don't rely on magnetic properties, so are unaffected by magnetic fields.

The main benefits of SSD technology compared to HDD can be summarised as:

  • they are more reliable, being less susceptible to shock and damage as they have no moving parts
  • they are considerably lighter (which makes them suitable for laptops, tablets and other modern devices)
  • they have faster access times than HDDs because they don't have to wait for the head to move and for the drive to spin
  • they have lower power consumption
  • they run much cooler than HDDs (both these points also make them very suitable for laptop computers)
  • because they have no moving parts, they can be very thin.

Solid state technology is also used in memory sticks (pen drives) and memory cards (e.g. SD and XD as used in cameras). Solid state technology is now employed in many laptops and tablets as well as in mobile phones, cameras and other portable devices. Small size, non-volatile memory and reliability are key features in such devices which need to be portable and also have minimum drain on the internal batteries.

SOLID STATE STORAGE DEVICES Internal Solid State USB Memory Stick Memory Card
Cost 4TB for £400 256GB for £20 128GB SD card £15
Capacity UP to 4TB 16MB to 256GB 32GB to 1TB
Data transfer speed Up to 3.5GB/s (Faster than magnetic disk because no moving parts) 3 -100MB/s Dependent on type of card and device interface
Portability Not portable, built into PC Very small, can put in a pocket or on a key-ring Very small, designed for portable devices
Durability More robust than hard disks with moving parts. Said to be 5-10 times more durable than a hard disk drive Very durable - some can be snapped quite easily Very durable - not sensitive to temperature or knocks
Reliability Extremely reliable Very reliable but can corrupt files if removed from PC too soon Very reliable
Typical use PCs, notebooks, tablets, laptops Personal use, moving files between computers In phones and cameras

NOTE: Memory sticks and memory cards are also referred to as off-line storage devices.

Q6: Look up some current prices and data transfer speeds of HDDs or SSDs. Is there a big difference in price and data transfer speed between the two types of storage?

Q7: Calculate the storage capacity (in GB) required for a database of 12,000 records, each 150 KB in size.

Optical devices

Optical media includes CD, DVD and Blu-ray discs.

The word 'optical' should make you think about the eye and how we see the world in terms of reflected light. Optical media work in a similar way. Lasers write data to the disc and read data from it.

CDs come in three different formats: read-only (CD-ROM), recordable (CD-R) and rewriteable (CD-RW). A CD-ROM is 'pressed' with the data at the time of manufacturing.

Optical storage devices have moving parts, which makes access times and data transfer speeds relatively slow in comparison with SSDs.

OPTICAL STORAGE DEVICES CD DVD Blu-ray
Cost 100 x 640MB CD-R for £20 (20p each) 50 x 4.7GB DVD-R for £12 (24p each) 50 x 25GB Blu-ray for £22 (44p each)
Capacity 640MB 4.7GB (single layer)
8.5GB (dual layer)
25GB (single layer)
50GB (dual layer)
Access Speed Up to 7.6 MB/s (52x) 16 MB/s (12x) 50 MB/s (12x)
Portability Easy to carry in a large pocket or bag
Durability Depends on how it is stored. Quality will degrade over time but the manufacturer's life expectancy is 10 to 25 years. Adversely affected by prolonged exposure to sunlight Depends on how it is stored. Quality will degrade over time but the manufacturer's life expectancy is 10 to 25 years. Adversely affected by prolonged exposure to sunlight Depends on how it is stored. Quality will degrade over time but the manufacturer's stated life expectancy is 20 to 100 years
Reliability Good for medium term but degrades over time (still an unknown quantity)
Typical use CD-ROM for software distribution, CD-R or CD-RW for backup/archive DVD is used as a back-up device but also for distribution of software, games and the storage of movies Blu-ray is used for storing of movies and games but also as a back-up device; very large storage capacity means it is replacing dvds

Exercises

Questions 1 to 3

  1. Here are some statements about the CPU of a computer.

    Tick one box in each row to show whether each of the following statements is true or false [5]

    • CPU stands for Central Processing Unit
    • The CPU fetches and decodes instructions
    • The speed of the CPU is usually measured in Gigahertz (GHz)
    • If a CPU has many cores, this slows down the computer
    • The hard disk is part of the CPU

    OCR A451/01 June 2013 Qu 1

  2. Circle the correct options in the following statements about computer architecture:

    (a) Holds the address of the next instruction to be executed.
    MDR    ALU    MAR    PC [1]

    (b) Data stored here is not erasable and usually contains instructions for booting the system and other important information.
    ALU    RAM    Cache    ROM [1]

    (c) Arithmetic and logical instructions are carried out here.
    ACC    MAR    ALU    CU [1]

  3. Alicia has designed a computer using Von Neumann architecture.

    (a) Describe the purpose of two registers that are used by Von Neumann architecture. [4]

    (b) The CPU has a clock speed of 3.8 GHz. Describe what is meant by a clock speed of 3.8 GHz. [2]

    (c) Alicia says: "My computer has a quad-core processor, so it will run twice as fast as a computer with a dual-core processor." Explain why this statement is not always true. [3]

    (d) The computer will only have 2GB of RAM, but Alicia says that virtual memory can be used instead of adding more RAM.

    (i) Explain how virtual memory can compensate for the lack of RAM in Alicia's computer. [3]

    (ii) Explain why it would be beneficial for Alicia to get more RAM instead of relying on virtual memory. [2]

    OCR J276/01 May 2018 Qu 4

Questions 4 to 6

  1. The CPU is the component which does most of the processing in a computer.

    (a) State two tasks which are carried out by the CPU when processing data. [2]

    (b) Explain how the clock speed and the cache size of the CPU affect its performance. [4]

    OCR A451/01 June 2012 Qu 7

  2. Most computers use at least one storage device.

    (a) Explain one reason why a secondary storage device is needed in most computer systems. [2]

    (b) Some secondary storage devices are magnetic and others are solid state.

    (i) Describe the characteristics such as capacity, reliability and portability of magnetic and solid state secondary storage. [6]

    (ii) Give a typical use for a magnetic storage device and a solid state storage device. [2]

  3. Shane has purchased an 8 GB memory card for his digital camera.

    Each photo taken requires 2.6MB of storage.

    Calculate the maximum number of photos that can be stored. [2]

Revision Quiz

Quiz Settings

Quiz Complete!