Você está na página 1de 8

Student notes - CPU Theory

The CPU
In terms of computing power, the CPU is the most
important element of a computer system. The CPU
actually carries out the fetching, decoding and
executing of instruction (one instruction at a time).

Two typical components of a CPU are:


• The Control Unit (CU), which (through using control on all other units of the
computer system) extracts instructions from memory, decodes and executes
them, calling on the ALU when necessary.
• The Arithmetic Logic Unit (ALU), which performs arithmetic and logical
operations.

The following diagram is one of the best possible representations of the internal
structure of the CPU:

The microprocessor is a special form of CPU found in microcomputers and


computerised devices, e.g. microwave oven.

System Clock
The main clock that controls the timing within a computer by generating a series of
pulses that are used to synchronize its circuits and operations
The clock rate is the frequency at which the clock generates pulses. The higher the
clock rate, the faster the computer may work. Each pulse is also referred to as cycle.
The frequency of pulse generation is measured in Hertz (Hz). One pulse is
equivalent to 1Hz.

CPU Speed
CPU speed is measured in Cycles per Second (Hertz). 1 Hz means cycle per
second.
A processor, whose speed is of 3 GHz, is able to process 3,000,000,000 (3 billion)
cycles in one second. The device which tracks the cycles is the system clock. The
following tables illustrate the units of measure used in measuring CPU speed:

CPU Speed
KHz – Kilo hertz 1,000 Hz 1 x 103Hz
MHz – Mega hertz 1,000,000 Hz 1 x 106Hz
GHz – Giga hertz 1,000,000,000 Hz 1 x 109Hz

Page 1 of 8
Student notes - CPU Theory

Units of Time
ms – millisecond 1ms = 0.1s = 1 x 10-1s
µs – microsecond 1 x 10-6s
ns - nanosecond 1 x 10-9s

Registers
Registers are special memory locations found inside the CPU, normally used for
specific purposes, where data or control information is temporarily stored. Some
registers are used in the different parts of the fetch execute cycle whilst others may
be available for use by the program being executed.
The registers handle/store the data currently used in the CPU. If data needs to be
stored for near future reference it is transferred to main memory and in case it is not
needed in the near future it is transferred to backing store, e.g. Hard disk.

Cache Memory
In between the registers and the main memory we usually find Cache Memory which
is a type of memory found in the CPU and holds that portion of data which is used
from the main memory. Both registers and cache memory offer high speed data
transfer.

The Control Unit (CU):

The main functions of the CU include;

The CU contains two registers:


1. Instruction Register (IR) – used to store a copy of the instruction currently being
executed
2. Program Counter (PC) – also referred to as the NIR (next instruction register)
since it stores the Address of the next instruction to be executed.

Page 2 of 8
Student notes - CPU Theory

The Arithmetic-Logic Unit (ALU):

The function of the ALU is;

The ALU also contains two registers,


1. The Accumulator – used to store current result of an operation
2. The Shift Register – operates ‘shifts’ to carry out multiplication or division

Memory Address Register (MAR) stores the address of the memory location
currently in use. In the fetch phase this would be the address of the instruction being
read and in the execute phase the address of the data being written to the main
memory.

Memory Data Register (MDR) stores the data being transferred to and from the
immediate access store (i.e. the data stored or which is going to be stored at the
address shown in the MAR). It acts as a buffer allowing the central processor and
memory unit to act independently without being affected by minor differences in
operation

Don’t forget that both instructions and data are simply groups of binary digits.

Main Memory and Addresses:


The main memory (i.e. RAM and ROM) is usually drawn as being part of the CPU’s
structure, but strictly it is not part of it. As highlighted before, Main memory is used
to store data which is not currently used by the CPU. Of course each block of data
needs to have its corresponding Memory Address. Think of a hotel where each guest
holds a Room Number used to refer to him/her.
00
01
10 Address of
Memory 11 memory
location location

Page 3 of 8
Student notes - CPU Theory

System Buses
There are three basic buses in the computer and are demonstrated in the diagram
below.

Every memory location where data is stored, has its own unique address. Therefore
since the memory has two parts – the address and the data store – we need to have
two separate busses: address bus and data bus.

The address bus transmits the address of a


memory location to the memory, so that the
microprocessor can either read the data from that
location or store data in it (through data bus).
There the address bus is like a one-way road
where the microprocessor only sends memory
addresses and expects no reply from this bus.

Once the main memory receives the address of a particular memory location, it
prepares itself to either copies and sends the data of that memory location to the
microprocessor (read process). Or start receiving data from the microprocessor to be
stored or written in the memory location specified by the address received from the
address bus (write process). All this is done via the data bus. Thus the data bus is
a two-way traffic road.

You are probably wondering how the data knows which way to go! This is the
function of the final connection, which forms part of the control bus. This particular
wire carries the signal to tell the memory whether a read or write operation is going to
take place (in practice a ‘1’ signal might mean read and a ‘0’ signal might mean
write).

Address Bus and Addressable Space:


A bus is a collection of data lines, a sort of wire, which in this case carries instructions
related to the address of a particular instruction or data. The address bus has a
particular width, i.e. the number of data lines. Since each line can represent a single
bit (0 = off, 1 = on), we use the terms 8-bit, 16-bit or 32-bit address bus. The width of
the bus corresponds to the number of locations (hotel rooms) which the bus can
address (possible combinations). This is referred to as the Address Space. The
address space is the number of memory locations which the address bus can locate.
Therefore an 8-bit address bus can handle up to 256 locations ranging from 0 to 255.
The address space for different bus width can be worked out as follows:

Address Space = 2n, where n = bus width

The Pentium has a 32-bit address bus. Hence it can handle 232 memory locations or
a total of 4GB of memory.

Page 4 of 8
Student notes - CPU Theory

Data Bus and Word Length:


The data bus is the ‘wires’ used to carry data to/from the CPU/Main Memory.

The width of the data bus refers to the ‘WORD LENGTH’ of the CPU, i.e. the
maximum data the CPU can handle at a time.

The larger the word size the faster the CPU.

Example:

Let’s say we have two processors, one is 633MHz and the other is 1.4GHz. How
much time would a 1 CPU cycle take in each processor?

Processor 1: 633MHz
633MHz = 633 million cycles per second = 633 x 106 = 633 000 000
Therefore 1 cycle takes 1/633 000 000 seconds (actual result in micro seconds)

Processor 2: 1.4GHz
1.4GHz = 1 billion and 400 million cycles per second = 1.4 x 109 = 1 400 000 000
Therefore 1 cycle takes 1/1 400 000 000 seconds (actual result in nano seconds)

Obviously the higher the frequency determined by the system clock (in Hz), the faster
the computer can go.

Page 5 of 8
Student notes - CPU Theory

Fetch-Execute Cycle
Further reading: Merlin pg 203, 204

Refers to the process whereby the control unit must first fetch an instruction
from main memory before it can execute (interpret) that instruction

THE FETCH-EXECUTE CYCLE


FETCH CYCLE : The CU
MAIN CONTROL UNIT
1. Fetches an instruction from memory
MEMORY
2. Decodes the instruction (determines 1 2
what it means). FETCH DECOD

EXECUTE CYCLE: The ALU


4
3. Executes the instruction STORE 3
4. Stores the processed results back to
EXECUTE
main memory. ARITHMETIC LOGIC UNIT

The Fetch Execute Cycle - Steps


The procedure of executing a program is known as fetch-execute-cycle and is
basically carried out in the following steps.

1. Set value of the PROGRAM COUNTER to the address of the 1st


instruction.
2. Fetch the instruction from the location specified by the PROGRAM
COUNTER.
3. Store a copy of this instruction in the INSTRUCTION REGISTER.
4. Increment the PROGRAM COUNTER by 1.
5. Execute the instruction i.e.;
i. Decode the instruction
ii. Fetch data from Main Memory and place it in Data
Register.
iii. Activate correct circuits to Carry out the instruction
iv. Move Result back to Main Memory

6. GOTO step 2

Page 6 of 8
Student notes - CPU Theory

The Instruction Set


The function of the CPU is to process data. The data is given to the CPU in the form
of instructions. The CPU when created is instructed to obey certain commands
known as the INSTRUCTION SET.

An instruction is made up from three fields:


1. The OPCODE – (Operation code) This indicates the operation to be
performed by the CPU, e.g. addition, data transfer. This code is made up of a
number of bits which determines the number of different operations which the
CPU can perform. (the Mnemonic part)

2. The OPERAND – the value part on which an opcode is working. this part
might not be present in a particular instruction but in the case of an addition
(as an example) the value/s to be added must be supplied as operands

Opcode Operand Explanation


LDA 32 Nil Loads the Value of the memory address 32
MOV AX 1 Moves the value ‘1’ into the register AX

Machine Code and Assembly Language


The opcodes used in the previous example are MOV and LDA. These two
abbreviations are called mnemonics. These are abbreviations used by programmers
when writing programs. However these can be used only when writing in ASSEMBLY
LANGUAGE.

Mnemonic - a code for an operation which is easily remembered. Using Mnemonics


rather than Binary numbers has the following advantages:
1. Programs are written faster
2. Mistakes are more easily found

MACHINE CODE is another example of a Low Level Language. It is actually the first
language used to make programs. This type of language contained strictly codes
made from 1’s and 0’s.

Machine Code and Assembly Language are the only two languages considered to
be Low Level Languages. Note also that ultimately ALL languages have to be
converted to Machine code for execution.

Page 7 of 8
Student notes - CPU Theory

Exercise
1. Draw and label a block diagram of CPU and Memory unit, showing clearly the
following items: ALU, Accumulator, Control unit, Program counter, Memory Data
register, Memory Address register, Data bus, Address bus and control bus
2. Explain the terms :
i. instruction set
ii. Opcodes and operands
3. Describe briefly the sequence of steps carried out during the fetch-execute cycle.
In your answer refer to the Program counter, main memory and instruction
register.
4. What do the following letters stand for?
•CPU
•CU
•ALU
5. What is a Bus? Name the 3 types of buses.
6. What are the two types of Main Memory? give their properties
7. What is the difference between Main Memory and Backing Storage.
8. What is the function of the System Clock?

Page 8 of 8

Você também pode gostar