Computers in the real world What is a CPU?

advertisement
Computers in the real world
Objectives
• Understand what role the CPU plays in a
computer
• Understand how CPU performance is
measured
• Look at the different parts of a CPU
• Explore the idea of an instruction set and run
simple programs in an assembly code
emulator.
Computers in the real world
What is a CPU?
• Remember the term micro-processor?
• The CPU is the microprocessor!
• CPU stands for
– Central Processing unit
– It is referred to as micro as, errr, its small 
• It is the brains of the computer
– It co-ordinates all of the hardware by running
software.
Computers in the real world
What is a CPU?
• Remember the term micro-processor?
• The CPU is the microprocessor!
• CPU stands for
– Central Processing unit
– It is referred to as micro as, errr, its small 
• It is the brains of the computer
– It co-ordinates all of the hardware by running
software.
Computers in the real world
How the CPU communicates
1. Software, like office, are stored
on the hard drive. To run the
software we must “load” it.
Software
Hard
drive
CPU
Memory
Computers in the real world
How the CPU communicates
Software
Hard
drive
2. The operating system (like
windows) will be running on the
CPU. When the user selects to
load office up, it is the OS which
starts it off.
CPU
Memory
Computers in the real world
How the CPU communicates
3. Software is loaded from the
hard drive and stored in main
memory
Software
Hard
drive
CPU
Memory
Computers in the real world
How the CPU communicates
4. The CPU then transfers
instructions from memory into the
CPU in order to run them. It does
this ONE at a time!
Software
Hard
drive
CPU
Memory
Computers in the real world
The bus
The CPU is connected to other devices using a bus. This is
a circuit which connects the devices together. It has 3
parts
Address bus – where to find data
Data bus – data is loaded/saved over this line
Control bus – says if it is loading or saving
Memory
CPU
Computers in the real world
What is an instruction?
A CPU can perform a set number of tasks such as
adding, subtracting etc. One of these is known as an
instruction.
All of the instructions together is known as a
instruction set.
CPU
Different types of micro-processor will have
different instructions sets.
Computers in the real world
What does an instruction look like?
Instructions on the CPU are written in binary
0001 1000 – A add instruction in binary
1 08 – The same instruction as a normal number
CPU
ADD 8 – What the computer sees and understands
Computers in the real world
Opcodes and data
Instructions have two parts to them.
ADD 8
Opcode
Data
The opcode tells the CPU what to do. ADD tells the CPU to add two numbers
together.
The data part of the instructions tells the CPU what to add. In this case 8.
The question is what do we add to? How does it work! What is this opcode?
All shall be revealed!
Computers in the real world
Instruction set of a simple computer
Below is a table showing the instructions of a simple computer called the
LMC or little man computer.
Opcode
Name
Data
Explanation
1xx
ADD
The number to add
It will add a value from a register to the current
value of the ACC
2xx
SUB
The number to subtract
It will subtract value from a register to the current
value of the ACC
3xx
STA
Stores a value into a register
Will take the contents of the ACC
5xx
LDA
Loads a value from a register
Will take a value from a register and store it in the
ACC
6xx
BRA
Line number to “jump” to.
Unconditional branch. Will jump to the given
instruction number.
7xx
BRZ
Line number to “jump” to.
Branch if zero. Will only jump if the ACC is zero
8xx
BRP
Line number to “jump” to.
Branch if positive. Will only jump if the ACC has a
positive value.
901
INP
Input from the user
Will input a value and store it in the ACC
902
OUT
None
Will output the contents of the ACC
Computers in the real world
Real CPU’s
Real CPU’s have different instruction sets. Programs written
in one instruction set CAN NOT be run on the other
ARM
x86
ARM processors tend to be
found on devices such as mobile
phones or other portable
devices. They have the
advantage of using less
electricity than desktop CPU’s
Desktop and laptop computers
use x86. This instruction set was
created a long time ago.
Companies such as Intel and
AMD create these types of
micro-processor. Each of these
companies add their own special
instructions in a attempt to
speed things up.
Computers in the real world
Think of instruction sets as...
Instruction sets can be thought of as a language. A French speaker could
not talk to a mandarin speaker as they would not understand each other
Computers in the real world
Registers
A register is a small block of FAST memory stored on the
CPU. Instructions will use the registers when they run
A CPU will have small blocks of memory called registers. These are used to
store calculations as the processor runs. As a program runs it will load / store
values into the registers until it comes to the final result.
Think of it like a table in your notebook. Each register can hold a separate
number!
Register
Value
1
8
2
5
3
1
Computers in the real world
ACC register
The ACC stands for accumulator. It is used in all calculations
and answers are ALWAYS stored into the ACC.
The ACC acts like the display on a calculator. What
happens when you type in.
10
+
5
=
The result is stored on the display! In fact the
calculator also uses an accumulator and has it’s own
micro-processor!
Hopefully that is not too surprising!
Computers in the real world
A sample program to add 2 numbers
The program below will display the result of adding 2
numbers.
INP
STA 1
INP
ADD 1
OUT
ACC Register 1 -
Let us look at how this program works.
Computers in the real world
A sample program to add 2 numbers
The program below will display the result of adding 2
numbers.
INP
STA 1
INP
ADD 1
OUT
ACC - 12
Register 1 -
INP – The user will be asked to enter a number onto the computer. The
user enters the value 12.
Computers in the real world
A sample program to add 2 numbers
The program below will display the result of adding 2
numbers.
INP
STA 1
INP
ADD 1
OUT
ACC - 12
Register 1 - 12
STA 1 – The ACC is then saved into register 1. If we did not then the next
INP instruction would overwrite it.
Computers in the real world
A sample program to add 2 numbers
The program below will display the result of adding 2
numbers.
INP
STA 1
INP
ADD 1
OUT
ACC - 5
12
Register 1 - 12
INP – The user will be asked to enter a number onto the computer. The
user enters the value 5.
Computers in the real world
A sample program to add 2 numbers
The program below will display the result of adding 2
numbers.
INP
STA 1
INP
ADD 1
OUT
ACC - 17
5
Register 1 - 12
ADD 1 – Will take the value in register 1 and add it to the ACC. It then
stores the result into the ACC
Computers in the real world
A sample program to add 2 numbers
The program below will display the result of adding 2
numbers.
INP
STA 1
INP
ADD 1
OUT
ACC - 17
Register 1 - 12
OUT– Will display the contents of the ACC on the screen.
Computers in the real world
parts of the CPU
A CPU has a number of different parts inside it.
CU
Registers
ALU
MU
CU – Control Unit
ALU – Arithmetic logic unit
MU – Memory unit
Computers in the real world
Control unit
The control unit will communicate to devices over the buses. For
example the hard drive or the graphics card. It also manages the CPU
to allow it to run instructions.
CU
Computers in the real world
ALU -
The arithmetic logic unit (ALU) will perform any maths related
operations and any comparisons. So instructions like ADD, SUB and
BRZ will be run by the ALU.
ALU
Computers in the real world
MU
The memory unit (MU) is responsible for communicating with
memory. It allows data to be loaded and saved. It is also referred to as
the Intermediate access store (or IAS)
MU
Computers in the real world
Activity
Make notes on the following in your revision power point.
The parts of a CPU
What is a register?
What does the ACC do?
Computers in the real world
Clock cycle
CPU’s are measured by something known as the clock speed. This is a
number measured in hertz. This says how many CPU cycles can be run
per second. The bigger the number the more clock cycles can be run
per second.
So a 2Ghz is technically slower than a 3Ghz processor.
Clock cycles are used to synchronize the CPU to ensure that the next
instruction is not run before the previous one has completed. The
shorter the cycle means the more instructions we can run in a single
second.
However some instructions need more than one clock cycle!
Computers in the real world
So higher clock rates are what we want?
Sadly no. Sometimes a CPU with a high clock speed (3.3Ghz) may be
slower than one with a lower clock speed (2.4Ghz). Although it does
mean more instructions can be run per second on a higher clock speed
there is a draw back to this. Most of the time the CPU is idle!!!
The reason why is that clock speed is only one measure of a CPU and is
certainly not the most important.
Other things you need to consider are –
•The architecture of the CPU
•If it is 32bit or 64bit
•The speed of the buses.
•Are there any bottle necks in the system (eg slow hard drive)
•How many cores are on the CPU?
•How big is the cache?
Computers in the real world
Architectures
CPU’s are put together in different ways. As CPU’s improve so does the
way they handle instructions and talking to hardware. Normally when
companies like Intel release a new processor architecture it will run at
a lower clock speed. They then will try to increase the clock speed until
the next architecture comes along.
For example in 1993 Intel released the Pentium processor. In 1997 they
then released the Pentium II processor. These both connected to the
motherboard using different slots.
A motherboard can only accept a very limited number of different CPU
architectures. As such when a new CPU architecture comes out it may
require a brand new way of connecting it to the CPU.
Computers in the real world
32 or 64 bit
Most CPU’s run in 64bit currently. However there are still a LOT of
processors still running in 32bit. So what does this mean?
Computers store numbers and other data in binary. 32 bits mean that
we can store up to 2,147,483,647 while in 64 bit we can store
9,223,372,036,854,775,807 . (signed integers). That means that we
can deal with bigger numbers more efficiently. This is great for doing
things like –
•Academic research (universities)
•Decoding/encoding movies and music
•Games!
IMPORTANT! Each piece of software must be compiled to work on
64bit. You can buy windows 64 bit but it does not mean your other
programs will also be 64bit!
Computers in the real world
Front side bus
Remember that buses connect the CPU to each of the other devices on
the computer. The bus is part of the motherboard.
Buses transfer data to and from the CPU. The rate at which data can
travel across this is measured in hertz. CPU’s are built to handle
different front side bus speeds. The faster the speed the faster data
can be transferred to/from the CPU.
IMPORTANT! The CPU will spend most of it’s time waiting for devices
to transfer data. Anything which can speed this up will greatly improve
the speed of the system.
Computers in the real world
Core blimey!
A dual or quad core processor essentially means that it can run
multiple instructions at the same time. Dual can run 2 and quad can
run 4. Each core acts like a separate processor.
This speeds up multitasking. Essentially it means that different
processes can be run on different cores. Reducing the load on a
individual core. However a single program gains NOTHING from extra
cores unless it has been programmed specifically to use them.
Having more cores will not improve the speed of a system unless you
are running lots of different programs which require a large amount of
CPU time.
Normally you are still restricted by bottle necks such as the hard drive
or the internet.
Computers in the real world
Speed mismatch – the true cause of a slow system!
A basic speed comparison!
CPU
memory
Hard drive
Internet
This graph shows the speed difference between how long it takes to
perform a task. The longer the bar the slower the device.
As you can see the CPU is much faster than the internet or even the
hard drive.
Computers in the real world
Bottlenecks in the system
So will a faster computer make your internet faster? The answer is
unlikely. It would be faster creating the page but the CPU would still
have to wait for the data to be sent over the telephone lines.
Your hard drive is also a big bottle neck. When you load a program or
load a file it needs to be transferred from the hard drive to memory.
While this is happening the CPU will not be doing much!
Computers in the real world
Really?
Yeah really! Look at the graph below -
This shows how busy the CPU is as a program is loaded (in this case
Microsoft publisher). The CPU is used for very short bursts then not
much else happens until another big burst.
The CPU is idle for most of the loading. This shows that the hard drive
is slowing the CPU down!
Computers in the real world
I like Cache!!
The cache is a small block of FAST memory stored either in the CPU or
in-between the CPU and memory. Anything stored in the cache can be
accessed MUCH faster than if it was accessed from main memory.
If you turned the cache off your computer would run at about 10% of
it’s current speed. Yes cache has that much of a impact on your
system!
So why do computer manufactures not tell you how big / last the
cache is? Well they think you guys are dumb and need things simple!
Next time your in PC world ask how much cache is in each laptop you
see. That will confuse them. Now you know what I do with my
weekends 
Computers in the real world
How does cache speed things up?
When programs are fetched from memory the are stored in the cache.
The CPU will look at the cache first for an instruction. If it is not in
cache then the CPU will access it from main memory which is much
slower. This is known as a cache miss.
Fetch instruction
Cache
ADD
SUB
BRA
Cache miss – Have to access from memory
Computers in the real world
The 80/20 rule
A computer spends 80% of its time in only 20% of the instructions.
Later you will find out why this is! Cache takes advantage of this by
putting that 20% of the code into the fast cache. That reduces the
amount of cache misses and thus increases the speed of the system as
whole!
Fetch instruction
Cache
ADD
SUB
BRA
Cache miss – Have to access from memory
Computers in the real world
Why not make memory our of the same stuff as cache?
Eventually they do! However there is some huge hurdles to overcome
for that and it takes memory manufacturers to make cache bigger and
enable it to act as main memory. Also there is a big cost factor. Cache
memory is very expensive so the more we use the more expensive the
system will be.
Bright computer science type people have worked out that the speed
increase you would get is very small over just having cache. This is
mainly due to the 80/20 rule.
Computers in the real world
Activity
Explain in as much detail as you can –
What effects the speed of a CPU?
Focus on the following ONLY
Cache
Cores
Clock speed
These are the main ones you need for the exam. The others I have
included for completeness.
Download