You are on page 1of 11

1.

3 HARDWARE AND SOFTWARE AHMED THAKUR

1.3.2 COMPUTER ARCHIECTURE AND THE FETCH-EXECUTE CYCLE

 Understanding of the basic Von Neumann model for a computer system and the stored program
concept (program instructions and data are stored in main memory and instructions are fetched
and executed one after another)

Computer Architecture
Very early computers were fed data whilst the machines were actually running. They weren’t able
to store programs; consequently, they weren’t able to run without human intervention. In about 1945,

R
John von Neumann developed the idea of a stored program computer, often referred to as the
VON NEUMANN ARCHITECTURE concept.

KU
His idea was to hold programs and data in a memory. Data would then move between the memory
unit and the processor.

There are many diagrams which show von Neumann architecture. Figures show two different ways
of representing this computer model. The first diagram is a fairly simple model whereas the second
diagram goes into more detail. Second figure shows the idea of how a processor and memory unit

A
are linked together by connections known as BUSES. This is a simple representation of von Neumann
architecture. These connections are described in Table.
TH
ED
HM

Following table describes the function of each of the three buses shown in Figure. Buses essentially
move data around the computer and also send out control signals to make sure everything is
A

properly synchronised.

COMPUTER SCIENCE https://www.facebook.com/groups/OAComputers/


ahmed_thakur@hotmail.com, 0300-8268885 Page 1
2210
1.3 HARDWARE AND SOFTWARE AHMED THAKUR

1.3.2 COMPUTER ARCHIECTURE AND THE FETCH-EXECUTE CYCLE

Type of bus Description Data/Signal Direction


carries signals relating to addresses (see unidirectional
Address bus later) between the processor and the (signals travel in one direction
memory only)
bi-directional
sends data between the processor, the
Data bus (data can travel in both

R
memory unit and the input/output devices
directions)
carries signals relating to the control and
unidirectional
coordination of all activities within the

KU
Control bus (signals travel in one direction
computer (examples include: the read and
only)
write functions)

Integrated Circuit
Communications between devices such as computers and printers and across networks is
performed adequately with serial lines. Data transmission over much shorter distances inside

A
integrated circuits (ICs) is best done using parallel channels. ICs employ three buses for
communication:

 Data bus: carries data between memory and processor and also between ports and other parts
e.g. sound card, graphics card, have own processors and memory and some data are moved
TH
to processor and main memory; bi-directional, data flow to processor and back to memory.

 Address bus: carries address from processor to location in main memory (some ports may be
memory-mapped so have addresses too); unidirectional, no need for an address to flow back
to processor.

 Control bus: carries signals from processor to parts of CPU and system to activate something e.g.
to read or write data to a memory location or I/O device.
ED

These buses use parallel channels rather than single, serial ones. Speed and throughput of data are
of prime concern in IC design so it makes sense to maximise this with as many lines as possible.
HM
A

COMPUTER SCIENCE https://www.facebook.com/groups/OAComputers/


ahmed_thakur@hotmail.com, 0300-8268885 Page 2
2210
1.3 HARDWARE AND SOFTWARE AHMED THAKUR

1.3.2 COMPUTER ARCHIECTURE AND THE FETCH-EXECUTE CYCLE

Following figure shows a slightly more detailed diagram of the von Neumann architecture. It brings
to our attention another new concept in this computer model – the idea of ADDRESSES and
REGISTERS. Addresses indicate where the data is stored and registers are needed so that data can
be manipulated within the computer.

R
KU
A
TH
ED

An address is the location of where data can be found in a computer memory. Each address in the
memory is unique. The addresses aren’t actually shown in Figure but they are contained in the part
of the diagram labelled memory unit. You will notice a number of items shown in the diagram known
as registers: MAR,
HM

MDR, ALU, PC and CIR. These are a little more complex and their function will be fully described in
the following pages. But essentially a register is simply a high speed storage area within the
computer. All data must be represented in a register before it can be processed. For example, if two
numbers are to be added, both numbers must be stored in registers and the result of the addition
must also be stored in a register.

Registers
A register is a discrete memory location within the CPU designed to hold temporary data and
instructions
A

.A modern CPU will hold a number of registers. There are a number of general purpose registers that
the programmer can use to hold intermediate results whilst working through a calculation or
algorithm.

Then there are special-purpose registers designed to carry out a specific role. Each of these registers
are given a name so that the programmer can write their software code to access them. Different
manufacturers of CPU chips call them by different names (which makes life interesting for a
professional programmer!)

COMPUTER SCIENCE https://www.facebook.com/groups/OAComputers/


ahmed_thakur@hotmail.com, 0300-8268885 Page 3
2210
1.3 HARDWARE AND SOFTWARE AHMED THAKUR

1.3.2 COMPUTER ARCHIECTURE AND THE FETCH-EXECUTE CYCLE

Program Counter (PC)


This holds the address in memory of the next instruction.
For example if the program counter has the address 305 then the next instruction will be at location
305 in main memory (RAM). When a program is running, the program counter will often just be
incrementing as it addresses one instruction after the other, e.g. 305, 306, 307. However, the
instructions will often modify the next address, for example, 305 becomes 39. What has happened is
called a 'jump instruction'. This is how the software programmer will cause different parts of his code

R
to run depending on some condition e.g. a conditional IF statement. It is also how an interrupt routine
is serviced. The program counter will be loaded with the starting address of the interrupt routine.

KU
Purpose of Registers
When a register is being used to move data /instructions from one part of the system to another, this
is called a buffer. If you are fetching data from main memory (RAM) that data would pass through
a buffer on the CPU before being loaded into another internal register e.g. the instruction register.

In the fetch-decode-exectue cycle (see next mini-website), registers are used extensively to move

A
data and instructions around the CPU. For example, the address of the next instruction is moved from
the program counter to the memory address register to initiate a read operation.

Features of Von Neumann Model

 Memory Unit
TH
The computer memory unit is made up of a number of partitions. Each partition consists of
an ADDRESS and its CONTENTS. The example shown here uses 8 bits for each address and 8
bits for the content. In a real computer memory, the address and its contents are actually
much larger than this.

The address will uniquely identify every LOCATION in the memory and the contents will be the
binary.
ED

Memory Address Contents


1111 0000 0111 0010
1111 0001 0101 1011
1111 0010 1101 1101
1111 0011 0011 1011
HM


1111 1100 1110 1010
1111 1101 1001 0101
1111 1111 1000 0010

Figure showed five examples of registers. Their function will be described later on, but for now,
the abbreviations stand for:
 MAR – memory address register
A

 MDR – memory data register


 ALU – arithmetic and logic unit
 PC – program counter
 CIR – current instruction register.

Let us now consider how the two registers (MAR and MDR) shown in the memory unit are
used.

COMPUTER SCIENCE https://www.facebook.com/groups/OAComputers/


ahmed_thakur@hotmail.com, 0300-8268885 Page 4
2210
1.3 HARDWARE AND SOFTWARE AHMED THAKUR

1.3.2 COMPUTER ARCHIECTURE AND THE FETCH-EXECUTE CYCLE

READ
Consider the READ operation. We will use the memory section shown in Table. Suppose we
want to read the contents of memory location 1111 0001; the two registers are used as
follows:
 The address of location 1111 0001 to be read from, is first written into the MAR (memory
address register):

R
MAR 1 1 1 1 0 0 0 1

KU
A ‘read signal’ is sent to the computer memory using the control bus.
 The contents of memory location 1111 0001 are then put into the MDR (memory data
register):

MAR 0 1 0 1 1 0 1 1

A
WRITE
Now let us consider the WRITE operation. Again we will use the memory section shown in
Table. Suppose this time we want to show how the value 1001 0101 was written into memory
location 1111 1101.

TH
The data to be stored is first written into the MDR (memory data register):

MAR 1 0 0 1 0 1 0 1

 This data has to be written into the memory location with the address 1111 1101; so this
address is now written into the MAR:

MAR 1 1 1 1 1 1 0 1
ED

• Finally, a ‘write signal’ is sent to the computer memory using the control bus and this
value will then be written into the correct memory location. (Again confirm this by
looking at Table.)

Processor
HM


The PROCESSOR contains the ARITHMETIC AND LOGIC UNIT (ALU). The ALU allows arithmetic
(e.g. add, subtract, etc.) and logic (e.g. AND, OR, NOT, etc.) operations to be carried out.
How this is used is explained in Fetch Execute Cycle.

 Control unit
The CONTROL UNIT controls the operation of the memory, processor and input/output
devices. It contains the CURRENT INSTRUCTION REGISTER (CIR) and the PROGRAM COUNTER
(PC). The CIR contains the current instruction during processing. The PC contains the address
of the next instruction to be executed.
A

Essentially, the control unit reads an instruction from memory (the address of the location
where the instruction can be found is stored in the Program Counter (PC)).

This instruction is then interpreted. During that process, signals are generated along the
control bus to tell the other components in the computer what to do. How this all fits together
with the other components of the von Neumann model is discussed in Fetch Execute Cycle.

 Input and output devices


The input and output devices are discussed in Input and Output Devices Section and are the
main method of entering data into and getting data out of computer systems. Input devices

COMPUTER SCIENCE https://www.facebook.com/groups/OAComputers/


ahmed_thakur@hotmail.com, 0300-8268885 Page 5
2210
1.3 HARDWARE AND SOFTWARE AHMED THAKUR

1.3.2 COMPUTER ARCHIECTURE AND THE FETCH-EXECUTE CYCLE

convert external data into a form the computer can understand and can then process (e.g.
keyboards, touchscreens and microphones). Output devices show the results of computer
processing in a humanly understandable form (e.g. printers, monitors and loudspeakers).

How all of these five registers are used by a typical computer system can be found in Section
– the fetch–execute cycle. Again other textbooks and websites will all have different ways of
showing how this cycle operates. The important thing is to get a good general understanding

R
of how the cycle functions.

KU
Interesting fact:
P.S. Turing also got his own bit of fame by framing the 'Universal Turing Machine' and even more
famously by devising the 'Turing Test' which is still used today to decide if a computer has fooled a
person into thinking they are conversing with another person rather than a computer.

Conclusion

A
The Von Neumann architecture has been incredibly successful, with most modern computers
following the idea. You will find the CPU chip of a personal computer holding a control unit and the
arithmetic logic unit (along with some local memory) and the main memory is in the form of RAM
sticks located on the motherboard.
TH
But there are some basic problems with it. And because of these problems, other architectures have
been developed. These alternatives will be discussed later.

 The stages of the fetch-execute cycle, including the use of registers

The fetch–execute cycle


To carry out a set of instructions, the processor first of all FETCHES some data and instructions from
memory and stores them in suitable registers. Both the address bus and the data bus are used in this
process. Once this is done, each instruction needs to be decoded before finally being EXECUTED.
ED

This is all known as the FETCH–EXECUTE CYCLE and is the last part of this puzzle.

Fetch
In the fetch–execute cycle, the next instruction is fetched from the memory address currently stored
in the Program Counter (PC) and is then stored in the Current Instruction Register (CIR). The PC is then
HM

incremented (increased by 1) so that the next instruction can be processed. This is then decoded so
that each instruction can be interpreted in the next part of the cycle.

Execute
The processor passes the decoded instruction as a set of control signals to the appropriate
components within the computer system. This allows each instruction to be carried out in its logical
sequence. Figure shows how the fetch–execute cycle is carried out in the von Neumann computer
model. As with most aspects of computer science, there will be slight variations on this diagram if
other textbooks or websites are consulted. The main aim is to end up with a clear understanding of
A

how this cycle works.

COMPUTER SCIENCE https://www.facebook.com/groups/OAComputers/


ahmed_thakur@hotmail.com, 0300-8268885 Page 6
2210
1.3 HARDWARE AND SOFTWARE AHMED THAKUR

1.3.2 COMPUTER ARCHIECTURE AND THE FETCH-EXECUTE CYCLE

The program counter (PC) contains the address of the memory


location of the next instruction which has to be fetched

This address is then copied from the PC to the memory address

R
register (MAR); this is done using the address bus

KU
The contents (instruction) at the memory location (address)
contained in MAR are then copied temporarily into the
memory data register (MDR)

A
The contents (instructions) of the MDR are then copied and
placed into the current instruction register (CIR)

The value in the PC is then incremented by 1 so that it now points


TH
to the next instruction which has to be fetched

The instruction is finally decoded and then executed by sending


out signals (via the control bus) to the various components of
the computer system
ED

Figure shows the actual stages that take place during the fetch–execute cycle, showing how each
of the registers and buses are used in the process (the first five boxes are part of the fetch cycle and
the last box is part of the execute cycle).

Seven stages in a von Neumann fetch-execute cycle (Paper 11, June 2015 – Q7.b)
HM

STAGE DESCRIPTION
the PC (program counter) contains the address of the next instruction to be
1
fetched
the address contained in the PC (program counter) is copied to the MAR
2
(memory address register) via the address bus
the instruction is then copied from the memory location contained in the MAR
3
(memory address register) and is placed in the MDR (memory data register)
the entire instruction is then copied from the MDR (memory data register) and
4 placed in the CIR (current instruction register)
A

the value in the PC (program counter) is then incremented so that it points


5
to the next instruction to be fetched
the address part of the instruction is placed in the MAR (memory address
6
register)
7 the instruction is finally decoded and is then executed 7

More…
The purpose of a CPU
The CPU is often described as the 'brain of the computer'.

COMPUTER SCIENCE https://www.facebook.com/groups/OAComputers/


ahmed_thakur@hotmail.com, 0300-8268885 Page 7
2210
1.3 HARDWARE AND SOFTWARE AHMED THAKUR

1.3.2 COMPUTER ARCHIECTURE AND THE FETCH-EXECUTE CYCLE

The purpose of the CPU is to process data. It is where all the searching, sorting, calculating and
decision making takes place in the computer.

So no matter what you do on your computer, whether it be writing an essay, looking at your
photographs or checking your emails, the CPU has dealt with all of the data and processing required
to make these tasks possible.

R
The fetch-decode-execute cycle
A standard process describes the steps needed for processing to take place. It is called the Fetch -
Decode - Execute cycle or sometimes simply called the Fetch-Execute Cycle.

KU
First of all, both the data and the program that acts upon that data are loaded into main memory
(RAM) by the operating system. The CPU is now ready to do some work.

1. FETCH
The first step the CPU carries out is to fetch some data and instructions (program) from main

A
memory then store them in its own internal temporary memory areas. These memory areas are
called 'registers'. This is called the 'fetch' part of the cycle.
TH
ED

For this to happen,


 The CPU makes use of a vital hardware path called the 'address bus'.
 The CPU places the address of the next item to be fetched on to the address bus.
HM

 Data from this address then moves from main memory into the CPU by travelling along
another hardware path called the 'data bus'.

You could imagine that it is a bit like a boat attendant at a lake calling in customers when their
time is up -- "Boat number 3, time to come in!" The 'address' of the boat is 3 and the 'data' is its
content. The boat is parked at a pier, which is like the internal register of the CPU.

2. DECODE
The next step is for the CPU to make sense of the instruction it has just fetched. This process is
called 'decode'.
A

The CPU is designed to understand a specific set of commands. These are called the 'instruction
set' of the CPU. Each make of CPU has a different instruction set. The CPU decodes the instruction
and prepares various areas within the chip in readiness of the next step.

3. EXECUTE
This is the part of the cycle when data processing actually takes place. The instruction is carried
out upon the data (executed). The result of this processing is stored in yet another register.

Once the execute stage is complete, the CPU sets itself up to begin another cycle once more.

COMPUTER SCIENCE https://www.facebook.com/groups/OAComputers/


ahmed_thakur@hotmail.com, 0300-8268885 Page 8
2210
1.3 HARDWARE AND SOFTWARE AHMED THAKUR

1.3.2 COMPUTER ARCHIECTURE AND THE FETCH-EXECUTE CYCLE

The Control Unit


In order to appreciate how the Fetch-Execute cycle works you need to have a basic understanding
of the three main parts of a CPU. These are the:
 Control Unit
 Immediate Access Store (IAS)
 Arithmetic and Logic Unit (ALU)

R
The Control Unit has three main jobs:
1. It controls and monitors the hardware attached to the system to make sure that the commands
given to it by the application software are used. For example, if you send something to print, the

KU
control unit will keep a check that the instructions are sent to the printer correctly.
2. It controls the input and output of data so that the signals go to the right place at the right time
3. It controls the flow of data within the CPU - which is the Fetch-Execute cycle described above.

A
TH
ED

The Immediate Access Store


This holds the data and programs needed at that instant by the Control Unit.
HM

The CPU reads data and programs kept on the backing storage and stores them temporarily in the
IAS's memory. The CPU needs to do this because Backing Storage (e.g. the hard disk) is much too
slow to be able to run applications directly.

For example, let's imagine that a modern CPU was slowed down to carry out one instruction per
second. In this scenario, the hard disk slowed down to an equivalent rate would take three months
to supply the data needed by the CPU!

So data and programs are first of all loaded into main memory then the CPU fetches just the part it
A

immediately needs and loads it into its own internal registers as part of the Fetch-Execute cycle.

The Arithmetic and Logic Unit (ALU)


This is where the computer processes data either by manipulating it or acting upon it. It consists of
two parts:
1. Arithmetic part - which does exactly what you think it should - it performs the calculations on the
data e.g. 3 + 2 = 5
2. Logic part - this deals with logic and comparisons. For example, it works out if one value is greater,
less than or equal to another.

COMPUTER SCIENCE https://www.facebook.com/groups/OAComputers/


ahmed_thakur@hotmail.com, 0300-8268885 Page 9
2210
1.3 HARDWARE AND SOFTWARE AHMED THAKUR

1.3.2 COMPUTER ARCHIECTURE AND THE FETCH-EXECUTE CYCLE

Clock speed
Computers can only do one thing at a time. It may appear that many things are happening
simultaneously, for example you may be listening to music while writing an essay and also
downloading some software in the background.

In reality, the computer can only process one instruction at a time. It is just that the machine is so fast,
to you, everything seems to happen at once.

R
A CPU processes digital data by taking each piece
of data one-at-a-time and doing something with
it. The amount of time that it has to process each

KU
piece of data is controlled by a quartz clock inside
the CPU.

With every tick of the clock, the CPU is able to


process one piece of data or execute one
instruction.

A
The CPU clock speed is measured in cycles per second. 1 cycle per second is also known as 1 Hertz
A computer running at 1GHz can carry out a thousand million instructions per second.

The clock on a modern desktop computer runs extremely quickly, typically three thousand million
times a second (3 GHz).
TH
It is hard to imagine just how fast this is, but it does mean that a CPU running at this clock speed can
handle a huge amount of data in a very short time. This is why you can listen to music on the
computer while you are also browsing the web and doing some work.

Naturally the speed of the clock determines the basic performance of the CPU - the faster it goes,
the more powerful the computer.
ED

Clock speed higher Clock speed lower


Faster performance but runs hotter and Lower performance, less costly, needs less
consumes more power. power - so good for battery life in laptops.
HM

Thus, if you wish to improve the performance of a computer, you could select a machine that has a
faster CPU

Overclocking
Some people try to get the most extreme performance out of their existing CPU. They do this by
'overclocking'. This means they adjust the clock to run faster than the CPU was really designed for.
However, this makes the CPU run hotter and so extra cooling fans also have to be purchased.

Number of cores
Now imagine that the clock cannot be sped up any more for technical reasons. How would you
A

improve performance?

A sensible way forward is to use two CPUs at the same time. The job in hand is shared between the
two CPUs.

In an ideal world, running two CPUs would give you twice the performance. In real life this is not quite
the case because many applications have not been written to take advantage of extra processors.
However, by having more than one processor, you would certainly see an improved performance.

COMPUTER SCIENCE https://www.facebook.com/groups/OAComputers/


ahmed_thakur@hotmail.com, 0300-8268885 Page 10
2210
1.3 HARDWARE AND SOFTWARE AHMED THAKUR

1.3.2 COMPUTER ARCHIECTURE AND THE FETCH-EXECUTE CYCLE

A modern processing device may contain two or even four CPUs. Some chip-making companies
call these CPUs 'cores'. So a dual-core device means it contains two CPUs and a quad-core contains
four.

The Cache
Most data is stored on the hard disk. When we use that data, it is loaded into Random Access

R
Memory (RAM) because it is much faster to access the data from RAM than from the hard disk.

KU
A
TH
When we looked at the 'immediate access store' earlier, we found out that the CPU needs to access
data very quickly. Although RAM is faster than the hard disk, it still isn't fast enough to cope with the
speed that the CPU needs to deal with data.

To appreciate this, image a race taking place between two cars, one is a powerful high speed sports
car and the other is an ordinary little run-about. Their task is to race across town but there are many
traffic lights in the way. The start flag goes down and the big car shoots off the line and the little car
ED

just tootles along, well behind. Moments later, the big car has to stop at a traffic light, so within a
minute the small car catches up once again. By the time the race is over, the big car is hardly in
front of the slow car because of all the traffic light delays. This is exactly what happens in a CPU. The
processor may sit around idly waiting for new data to arrive and so it appears less powerful than it
really is.
HM

The way around this, is to store as much data as possible, as close as possible to the CPU to avoid
delays. This nearby storage area is called the 'cache'.

The cache is a special type of computer memory which can be accessed much faster than RAM.
The CPU looks in the cache for the data it needs. If the data is there, it will retrieve it and process it.
If the data is not there, then the CPU accesses the system memory and then puts a copy of the new
data in the cache before processing it.

Cache memory is volatile i.e. when the computer is shut down, the data stored there is lost.
A

Thus, in order to improve the computer's performance, it is important to keep the local cache full at
all times so that the CPU doesn't have to wait around with nothing to do.

The larger the cache size, the better the performance because you are able to store more data
locally.

COMPUTER SCIENCE https://www.facebook.com/groups/OAComputers/


ahmed_thakur@hotmail.com, 0300-8268885 Page 11
2210

You might also like