Professional Documents
Culture Documents
23-Oct-16
The CPU 2
In this chapter:
Review of computer arithmetic
Instruction sets
Processor structure and function
The control unit
23-Oct-16
Computer Arithmetic 3
Concerns:
The way in which numbers are represented
(binary format)
Algorithms used for basic operations (add,
subtract, multiply, divide)
Commonly performed on two different types of
numbers:
Integer
Floating point
Representation chosen is crucial issue
23-Oct-16
The ALU 4
ALU:
Part of computer that performs arithmetic and
logical operations on data
All other components are there to service ALU
Core of the computer
Based on simple digital logic devices that can
store binary digits and perform simple Boolean
logic operations
23-Oct-16
The ALU 5
Control unit:
provides signals that control operation of ALU & movement
of data into and out of ALU
Registers:
present data to ALU and store results of operation
Flags:
set as a result of an operation
23-Oct-16
Integer representation 6
i 0
23-Oct-16
Integer representation 8
Signed-Magnitude Representation
Simplest form of representation
In an n-bit word, rightmost n-1 bits hold
magnitude
In general,
n2 i
2 ai if an1 0
i 0
A n2
2i a
i 0
i if an1 1
23-Oct-16
Integer representation 9
Drawbacks:
Signs and magnitudes should be considered in
addition and subtraction
Two representations of 0:
+010 = 00000000
-010 = 10000000
Which is difficult to test for 0
Because of these drawbacks, it is rarely used
23-Oct-16
Integer representation 10
23-Oct-16
Integer representation 11
Negation
Sign-magnitude: invert sign bit
Twos complement:
Take Boolean complement of each bit
Treating result as unsigned, add 1
E.g.
00010010
Bitwise complement, 11101101
+ 1
23-Oct-16 11101110 = -18
Integer Arithmetic 15
Special cases:
For A = 0
E.g. consider 8-bit representation:
0 = 00000000 (twos complement)
Bitwise comp = 11111111
+ 1
100000000 = 0
The carry out of msb is ignored; so
negation of 0 is 0
23-Oct-16
Integer Arithmetic 16
Subtraction rule:
To subtract one no (subtrahend) from
another (minuend), take the twos
complement (negation) of the subtrahend
and add it to the minuend.
23-Oct-16
Addition and Subtraction 20
0010 = 2 0101 = 5
Examples: +1001 = -7 +1110 = -2
1011 = -5 0011 = 3
B Register A Register
Complementer
SW
OF Adder
23-Oct-16
Multiplication 22
23-Oct-16
Multiplication 24
Hardware implementation
23-Oct-16
Reading Assignment 25
Multiplication:
Text: pp 302 – 317
Floating point Arithmetic:
Text: pp317 – 328
23-Oct-16
Micro Operations 26
Examples of µops:
Shift, count, clear, load, increment
4 categories:
Register transfer µops
Arithmetic µops
Logic µops
Shift µops
23-Oct-16
Microoperations (µops) 29
23-Oct-16
Microoperations (µops) 30
Clock
Load
Transfer occurs here
23-Oct-16
Microoperations (µops) 31
3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0
3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0
23-Oct-16
Microoperations (µops) 32
Memory Transfer:
Read operation – from M to outside:
Read: DR M[AR]
Write operation – new info to M:
Write: M[AR] R1
23-Oct-16
Microoperations (µops) 34
Arithmetic µops
Basic arithmetic µops:
Addition, subtraction, increment and shift
Add:
R3 R1 + R2
=> HW implementation requires 3 registers and
adder
Subtract:
R3 R1 + R2’ + 1
other arithmetic µops:
R2 R2’, R2 R2’+1
R1 R1+ 1,
23-Oct-16 R1 R1 - 1
Microoperations (µops) 35
Hardware implementation
E.g 1) adder subtractor:
B3 A3 B2 A2 B1 A1 B0 A0
FA C3 FA C2 FA C1 FA C0
C4 S3 S2 S1 S0
A3 A2 A1 A0 1
x y x y x y x y
HA HA HA HA
C S C S C S C S
C4 S3 S2 S1 S0
23-Oct-16
Microoperations (µops) 37
Logic µops
Specify binary operations for strings of bits stored in
registers
Consider each bit separately
Examples:
XOR: p: F AΘB
Clear: p: F 0
AND: p: F A Λ B
Transfer: p: F A
OR: p: F A V B
23-Oct-16
Microoperations (µops) 38
HW implementation
Most computers use only AND, OR, XOR and
complement
0 Function table
Bi S1 S0 Output -operation
1 4X1 0 0 F=AB AND
F 0 1 F = AB OR
MUX i
2 1 0 F=AB XOR
1 1 F = A’ Complement
3 Select
S1
S0
23-Oct-16
Microoperations (µops) 39
Shift µops
Used for serial transfer of data
Logical shift transfers 0 through the serial I/P
E.g. R shl R Shift-left register R
R shr R Shift-right register R
R cil/cir R Circular shift register R
R ashl/ashr R Arithmetic shift reg R
e.g. ashr implementation:
sign
bit
23-Oct-16
Microoperations (µops) 40
Function table
S
MUX H0
0 select Output
1
A0 S H0 H1 H2 H3
S
A1
MUX H1 0 IR A0 A1 A2
0
1
A2 1 A1 A2 A3 IL
A3
S
MUX H2
0
1
S
MUX H3
0
1
Serial
23-Oct-16
input (IL)
Microoperations (µops) 41
D i
Arithmetic
Circuit
Select
0 4x1 F
C i+1 i
1 MUX
2
3
E i
Logic
B i
Circuit
A
i
shr
A i-1
shl
A
23-Oct-16 i+1
Instruction Sets: characteristics and 42
Functions
Computer instruction: binary code that
specifies sequence of µops for the computer
Operation of the processor: determined by
instruction it executes
Referred to as machine instructions
Instruction set: collection of different
instructions that the processor can execute
Every computer has its own instruction set
23-Oct-16
Machine Instruction Fields 43
Each instruction must contain the information required by
the CPU for execution
Machine language instructions usually are made up of
several fields.
The major two fields are:
- Opcode (Operation Code): specifies the particular operation
that is to be performed.
E.g. ADD, MOV, LOAD, etc…
- Operands: specifies where to get the source and destination
operands for the operation specified by the opcode.
- Instruction can normally have one or two operands (source
operand, destination operand) and there are some
instructions with no operand also.
23-Oct-16
Contd… 44
23-Oct-16
Machine Instruction Cha-cs 46
Instruction Representation:
Each instruction is represented by sequence of
bits
Instruction is divided into fields
More than one format with most instruction sets
E.g. simple instruction format (16-bit):
23-Oct-16
Machine Instruction Cha-cs 49
0 1 39
a) Number word
0 8 20 28 39
23-Oct-16
Machine Instruction Cha-cs 50
Instruction representation:
Binary representation – difficult to deal with
Common practice – to use symbolic representation.
i.e.:
Opcodes – represented by abbreviations – mnemonics
that indicate operations
E.g. ADD – Add, SUB – Subtract,
DIV – Divide
Operands – also represented symbolically
e.g. ADD R, Y
Each symbolic opcode has a fixed binary representation
Programmer specifies location of each symbolic
23-Oct-16 operand
Machine Instruction Cha-cs 51
Instruction Types:
High-level language – expresses operations in concise
algebraic form using variables
Machine language – in basic form, involving movement
of data to/from registers
E.g: in C/C++, X = X + Y;
in machine, LOAD X, M[addr1]
ADD X, M[addr2]
STORE X, M[addr1]
23-Oct-16
Machine Instruction Cha-cs 52
Instruction Types:
data processing : arithmetic and logic
instructions
data storage : memory instructions
Data movement : I/O instructions
Control : test and branch instructions
23-Oct-16
Machine Instruction Cha-cs 54
Types of Operands:
Machine instructions operate on data
Most important general categories of data are:
Addresses : are a form of data
Numbers :
which all machine languages include
3 types: integer, float, decimal
Characters : represented by sequence of bits; no of codes
available, e.g. ASCII – 7/8 bit
Logical data : n-bit unit of data considered as n 1-bit items of
data each having 0 or 1
Type: determined by operation being performed
23-Oct-16
Types of Operands 55
Addresses:
Are a form of data
To determine address, calculation must be
made on operand reference
In this context, addresses are considered to be
unsigned integers
23-Oct-16
Types of Operands 56
Numbers:
Included in all machine languages
Numbers stored in a computer are limited:
In magnitudes that can be represented
In precision (floats)
Thus programmer has to understand
consequences of rounding, overflow and
underflow
23-Oct-16
Types of Operands 57
Packed decimal …
To form the numbers, 4-bit codes are strung
together:
E.g. 246 = 0000 0010 0100 0110
Less compact but avoids conversion overhead
-ve numbers: a 4-bit sign digit at either end of
the string
Many machines provide arithmetic
instructions for performing operations
directly on packed decimal nos.
23-Oct-16
Types of Operands 59
Characters:
Common form of data
Not easy to process/transfer
Number of codes to represent characters by bits:
E.g. Morse code (the earliest!)
ASCII – each character represented by 7-bit
pattern; some of the patterns represent
control characters
EBCDIC – an 8-bit code used in IBM
mainframes
23-Oct-16
Types of Operands 60
Logical Data:
Each addressable n-bit data viewed as n 1-bit
items, with values 0 or 1
Advantages:
To store array of data items with values only
0 or 1
To manipulate bits of data item
Note: “type” of a unit of data is determined by the
operation being performed on it
23-Oct-16
Machine Instruction Cha-cs 61
23-Oct-16
Types of Operations 63
Data transfer:
Most fundamental type of machine instruction
It specifies:
Location of source and destination operands,
e.g. M, R, top of stack
Length of data to be transferred
Mode of addressing for each operand
E.g. MOVE, STORE, LOAD, EXCHANGE,
PUSH, POP,…
The simplest type in terms of processor action
23-Oct-16
Types of Operations 65
Arithmetic:
Basic operations: ADD, SUBTRACT, MULT,
DIVIDE
Provided in most machines (for fixed/floating
point)
Other single operand instructions:
ABSOLUTE, NEGATE, INCREMENT,
DECREMENT
Execution may involve data transfer operations
23-Oct-16
Types of Operations 66
Logical:
Provided by most machines for manipulating
individual bits
Based up on Boolean operations, NOT, AND,
OR, XOR, (most common)
E.g. if [R1]=10100101, [R2]=00001111, then
[R1]AND[R2] = 00000101 (masking)
In addition, variety of shift and rotate
instructions:
SHR, SHL, ASHR, ASHL, ROR, ROL
23-Oct-16
Types of Operations 67
Conversion:
Change/operate on format of data
E.g. TRANSLATE, CONVERT
Translation e.g. from EBCDIC to ASCII, binary
to BCD, …
I/O:
Only a few are provided in many
implementations
E.g. IN, OUT
23-Oct-16
Types of Operations 68
System control:
Those that can be executed only while processor
is in a certain privileged state
Typically preserved for use of operating system
E.g. instruction to alter a control register
Transfer of control:
To change sequence of instruction execution
E.g. JUMP, RET, EXEC, SKIP,HALT,
WAIT, NOP
23-Oct-16
Addressing Modes 69
Instruction
Opcode Operand
23-Oct-16
Direct Addressing 71
23-Oct-16
Direct Addressing Diagram 72
Instruction
Opcode Address A
Memory
Operand
23-Oct-16
Indirect Addressing 73
Instruction
Opcode Address A
Memory
Pointer to operand
Operand
23-Oct-16
Register Addressing 75
Instruction
Opcode Register Address R
Registers
Operand
23-Oct-16
Register Indirect Addressing 77
23-Oct-16
Register Indirect Addressing Diagram 78
Instruction
Opcode Register Address R
Memory
Registers
23-Oct-16
Displacement Addressing 79
EA = A + (R)
Address field hold two values
- A = base value
- R = register that hold displacement
- or vice versa
23-Oct-16
Displacement Addressing Diagram 80
Instruction
Opcode Register R Address A
Memory
Registers
Pointer to Operand +
Operand
23-Oct-16
Assembly Language 81
23-Oct-16
Assembly Language 83
Binary program:
Address Contents
100 0000 0001
101 0000 0011
102 0000 0010
Data:
Address Contents
200 0000 0011
201 0000 0100
202 0000 0000
This
23-Oct-16
is clearly tedious and error-prone task!
Assembly Language 84
A slight improvement:
Write the program in hex – as a series of lines:
Address Contents
100 01
101 05
102 02
…
200 03
201 04
202 00
23-Oct-16
Assembly Language 85
Stacks
Instruction formats
23-Oct-16
Processor Structure and Function: 87
Processor Organization
CPU must:
Fetch instructions
Interpret instructions
Fetch data
Process data
Write data
23-Oct-16
Processor Organization 88
23-Oct-16
Processor Organization 89
23-Oct-16
Processor Organization 90
23-Oct-16
Register Organization 91
23-Oct-16
Register Organization 93
Data registers:
Used only to hold data
Cannot be employed in calculation of operand
address
Address registers:
Can be general purpose or devoted particular
addressing mode
Examples:
Segment registers – to hold base address of a
segment in segmented memory
Index registers – for indexed addressing
23-Oct-16
Stack pointer – points to top of stack
Register Organization 95
Design issues:
General purpose or specialized use:
Make them general purpose
o Increase flexibility and programmer
options
o Increase instruction size & complexity
Make them specialized
o Smaller (faster) instructions
o Less flexibility
23-Oct-16
Register Organization 96
No. of registers:
Between 8 – 32 is optimum
Fewer = more memory references
More does not reduce memory references
and takes up processor real estate
Register length:
Large enough to hold full address
Large enough to hold full word
Often possible to combine two data registers
23-Oct-16
Register Organization 97
Condition codes:
Hold condition codes (also referred to as flags)
Bits set by processor hardware as result of
operations
E.g. result of last operation was zero
Can be read (implicitly) by programs
e.g. Jump if zero
Can not (usually) be set by programs
23-Oct-16
Register Organization 98
23-Oct-16
Register Organization 99
Organization
Two 16-bit microprocessors
23-Oct-16
10
Instruction Pipelining 1
23-Oct-16
10
Instruction Pipelining 2
23-Oct-16
10
Instruction Pipelining 3
23-Oct-16
10
Instruction Pipelining 4
23-Oct-16
10
Instruction Pipelining 5
23-Oct-16
10
Instruction Pipelining 6
23-Oct-16
10
Instruction Pipelining 7
23-Oct-16
10
Instruction Pipelining 8
23-Oct-16
10
9
Logic to account
for branches and
interrupts:
23-Oct-16
11
Alternative Pipeline Depiction 0
23-Oct-16
11
Pipeline Performance 1
max[ i ] d m d 1 i k
i
23-Oct-16
11
Pipeline Performance 2
Where:
τi = time delay of circuitry in the ith stage
τm = maximum stage delay (delay thru stage
which experiences the largest delay)
k = no of stages in the instruction pipeline
d = time delay of latch
In general, time delay d is equivalent to a
clock pulse and τm >> d
23-Oct-16
11
Pipeline Performance 3
Tk ,n [k (n 1)]
First instruction – requires k cycles to complete
Remaining (n – 1) instructions – require n – 1 cycles
E.g. The ninth instruction completes at time
cycle 14:
14 = [6 + (9 – 1)]
23-Oct-16
11
Pipeline Performance 4
23-Oct-16
11
Plot of Sk vs k 6
23-Oct-16
11
Exercise: 7
23-Oct-16
11
Reading Assignment 8
Pipeline Hazards
RISC- Reduced Instruction Set Computer
CISC versus RISC Characteristics
23-Oct-16
11
The Control Unit 9
23-Oct-16
12
The Control Unit 0
23-Oct-16
12
The Control Unit 1
Microoperations:
Each instruction is made up of a no of smaller
units (e.g. fetch, indirect, execute, interrupt)
These again consist of series of steps - µops
µops – Are atomic operations of processor
E.g. fetch cycle:
t1: MAR [PC]
t2: MBR Memory
PC [PC] + I
t3: IR [MBR]
23-Oct-16
12
The Control Unit 2
Functional requirements:
Those functions that the control unit must
perform
Defining these is basis for the design and
implementation of the control unit
Three step process to characterize CU:
Define basic elements of the processor
Describe µops that the processor performs
Determine function of CU to cause µops
23-Oct-16
performed
12
The Control Unit 4
23-Oct-16
12
The Control Unit 5
functional description of CU
Two tasks of CU:
Sequencing: cause processor to step thru a
series of µops in proper sequence
Execution: causing each µop to be
performed
It does these by use of control signals
I/P &O/P control signals – external
specifications
23-Oct-16
12
The Control Unit 6
General model of CU
23-Oct-16
12
The Control Unit 8
Inputs:
Clock:
for “keeping time”
CU causes one µop to be performed for each clock
pulse
Processor cycle time
Instruction register:
Opcode determines which µop to perform during
execute cycle
Flags:
To determine status of the processor and outcome
23-Oct-16
of previous operations (e.g. ISZ)
12
The Control Unit 9
Outputs:
Control signals within the processor – two types:
Those that cause data to be moved from one
register to another
Those that activate specific ALU functions
Control signals to control bus – also two types:
Control signals to memory
Control signals to I/O modules
All of these signals applied as binary inputs to
individual logic gates
23-Oct-16
13
The Control Unit 0
Implementation …
A unique logic i/p is produced for each opcode
by using decoder
Clock – issues repetitive sequence of pulses –
for measuring duration of pulses
23-Oct-16
13
The Control Unit 2
23-Oct-16
13
The Control Unit 3
PQ = 01 – execute, …
Then the Boolean expression will be:
C1 = P’Q’.T2
So, for every memory read instruction, this same
process is repeated
23-Oct-16
13
The Control Unit 5
Microprogrammed control
Hardwired :
difficult to design
Inflexible
Alternative:
Microprogrammed control implementation
Control variables at any given time can be
represented by a string of 1’s and 0’s called
control word
Control word can be programmed to perform
23-Oct-16 various and stored in memory
13
The Control Unit 6
23-Oct-16
13
The Control Unit 7
Microprogram
Program stored in memory that generates all the
control signals required to execute the instruction set
correctly
Consists of microinstructions
Microinstruction
Contains a control word and a sequencing word
Control Word - All the control information required
for one clock cycle
Sequencing Word - Information needed to decide
the next microinstruction address
Vocabulary to write a microprogram
23-Oct-16
13
8
THANK YOU!!!!
23-Oct-16