You are on page 1of 26

College of Computer Science

Chapter 3

Central Processing Unit


Course CSM344 : Computer Organization
Contents

> Processor Structure


> Basic CPU function
> Instruction cycle
> Control Unit operation
> Control unit design and implementation
> Timing & Control
> Micro operations
> Performance of the CPU
2
CPU basics

A typical CPU has three major


components:

> Register set

> Arithmetic Logic Unit (ALU)

> Control Unit (CU)

3
Register Set

> Registers are essentially extremely fast memory locations


within the CPU.

> Registers are used to create and store the results of CPU
operations.

> Different Computers have different register sets.

> They differ in the number of registers, register types, and


the length of each register.

4
Register types

> General-purpose registers can be used for multiple


purposes and assigned to a variety of functions by the
programmer.

> Special-purpose registers are restricted to only


specific functions.

— Address registers may be dedicated to a particular addressing


mode.

— Status registers is used to hold processor status bits, or flags.


These bits are set by the CPU as the result of the execution of
an operation.

5
Status register (Program Status Word)

The PSW contains bits that are set by the CPU to indicate the
current status of an executing program (arithmetic operations,
interrupts, processor status).

> Typical:
— Sign of last result
— Zero
— Carry
— Equal
— Overflow
— Interrupt enable/disable
— Supervisor mode (enable privileged instructions)

8
Example of Register Organizations (8086)

9
Arithmetic and Logic Unit (ALU)

> The component that performs the arithmetic and logical operations

> Load the operands into memory – bring them to the processor –
perform operation in ALU – store the result back to memory or
retain in the processor.

10
CPU Instruction cycle

12
Fetch Cycle

The sequence of events in fetching an instruction can be summarized as


follows:
1. The contents of the PC are loaded into the MAR.
2. The value in the PC is incremented.
3. As a result of a memory read operation, the instruction is loaded into
the MDR.
4. The contents of the MDR are loaded into the IR.

13
Execution Cycle : Execute Simple Arithmetic
Operation
Add R1, R2, R0
This instruction adds the contents of source registers R1 and R2, and stores
the results in destination register R0. This addition can be executed as follows:
1. The registers R0 , R1 , R2 , are extracted from the IR.
2. The contents of R1 and R2 are passed to the ALU for addition.
3. The output of the ALU is transferred to R0.

14
Instruction format

> Instruction typically has

— Opcode field - set of bits telling which instruction

— Address fields - memory or register address where operands


will be found.

Opcode Address of operands

15
Example of Program Execution (1)

> Instruction form for hypothetical machine


— 4-bit opcode field - 16 instruction types
— 12-bit address field- 4096 memory cells
Opcode Address
0110 001101010011

Opcode Name Effect


1 (0001) Load Load AC from memory
2 (0010) Store Store AC to memory
5 (0101) Add Add to AC from memory

16
Control Unit operation

> All computer operations are controlled by the control unit.

> The timing signals that govern the I/O transfers are also
generated by the control unit.

> On a regular processor, the control unit performs the tasks


of fetching, decoding, managing execution and then storing
results.

Register
File ALU

Control Unit
18
Timing & Control (1)

> All sequential circuits in the Basic Computer CPU are driven by a
master clock.
> At each clock pulse, the control unit sends control signals to control
inputs of the bus, the registers, and the ALU.

Machine
Cycle
1 2 3 4 5 6 7

Fetch Cycle Execution Cycle Fetch Cycle

Instruction Cycle Instruction Cycle

19
Timing & Control (2)

20
Control unit design and implementation

> Control unit design and implementation can be done by two general
methods:

— A hardwired control unit is designed from scratch using


traditional digital logic design techniques to produce a minimal,
optimized circuit. In other words, the control unit is like an ASIC
(application-specific integrated circuit).

— A microprogrammed control unit is built from some sort of


ROM. The desired control signals are simply stored in the ROM,
and retrieved in sequence to drive the microoperations needed
by a particular instruction.

21
Hardwired Control Organization

> This approach is to physically connect all of the control lines to the
actual machine instructions.

> The instructions are divided up into fields, and different bits in the
instruction are combined through various digital logic components to
drive the control-lines.

> The control unit is implemented using hardware (for example:


NAND gates, flip-flops, and counters).

22
Microprogrammed Control Organization

> A control unit whose binary control variables are stored in


memory is called a micro programmed control unit.

23
Example

24
CPU Performance

> There are various facets to the performance of a


computer.
• A metric for assessing the performance of a computer helps
comparing alternative designs.
• Performance analysis should help answering question such as
how fast can a program be executed using a given
computer?
• The clock cycle time is defined as the time between two
consecutive rising edges of a periodic clock signal.

25
Performance Measures

> We denote the number of CPU clock cycles for executing a job to be
the Cycle Count (CC), the Cycle Time by CT, and the clock
frequency by f = 1 / CT.

> The time taken by the CPU to execute a job can be expressed as:

CPU time = CC * CT = CC / f

> It is easier to count the number of instructions executed in a given


program as compared to counting the number of CPU clock cycles
needed for executing that program.

> Therefore, the average number of clock cycles per instruction


(CPI) has been used as an alternate performance measure.
26
Performance Measures

> The following equation shows how to compute the CPI:

27
Performance Measures

A different performance measure that has been given a lot of attention in


recent years is MIPS – million instructions-per-second (the rate of
instruction execution per unit time) and is defined as follows:

28
Performance Measures

MFLOPS - Million Floating-Point Instructions per second, (rate of floating-


point instruction execution per unit time) has also been used as a measure
for machines‘ performance. MFLOPS is defined as follows:

29
Performance Measures

Speedup is a measure of how a machine performs after some


enhancement relative to its original performance. The following
relationship formulates Amdahl’s law:

30

You might also like