3 CPU Part1
3 CPU Part1
CHAPTER 3
THE CENTRAL PROCESSING
UNIT (CPU)
Outline
2
Types of Operations
Addressing Mode
Instruction Format
Machine Code
encoded in binary – for machines to work with
𝐴−𝐵
𝑌=
𝐶+𝐷×𝐸
Instruction Comment
SUB Y, A, B Y A-B
MPY T, D, E T DxE
ADD T, T, C T T+C
DIV Y, Y, T Y Y/T
𝐴−𝐵
𝑌=
𝐶+𝐷×𝐸
Instruction Comment
MOVE Y, A YA
SUB Y, B Y Y-B
MOVE T, D TD
MPY T, E T TxE
ADD T, C T T+C
DIV Y, T Y Y/T
(b) Two-address instructions
Number of Addresses …
15
Instruction Comment
LOAD D AC D
MPY E AC ACxE
ADD C AC AC+C
𝐴−𝐵 STOR Y Y AC
𝑌=
𝐶+𝐷×𝐸 LOAD A AC A
SUB B AC AC-B
DIV Y AC AC/Y
STOR Y Y AC
More addresses
More complex instructions
More registers
Inter-register operations are quicker
Fewer instructions per program
Operation repertoire
How many ops?
What can they do?
How complex are they?
Built-In Data types supported
Instruction formats – how to encode as binary values
Length of op code field
Number of addresses
Instruction Set Design …
21
Registers
Number of CPU registers available
Which operations can be performed on which
registers?
Addressing modes
Types of Operand
22
Data Transfer
I/O
Arithmetic
Logical
Conversion
System Control
Transfer of Control
Data Transfer
24
Performed by ALU
Basic arithmetic operations provided by most machines
are:
Add, Subtract, Multiply, Divide
◼ Signed Integer
◼ Floating point
May include
Increment
Decrement
Negate
Absolute
Logical
26
arithmetic
shift
keep sign !
rotate
Conversion
28
Transfer data
From the computer to peripheral devices
From peripheral devices to the computer system
Branch
Also called jump instruction
Its operand is the address of the next instruction to be fetched and
executed
Two types of branches
◼ Conditional and unconditional
Unconditional branch
e.g. branch to instruction at location xxxx
Conditional Branch
e.g. branch to instruction at location xxxx if result of
last operation was zero
Transfer of Control …
32
Skip
Implies that the next instruction be skipped
Procedure call
Procedure
A self contained block of code
It can be called/invoked from any point in the program
Register
◼ RN PC +1 ; PC X
Start of called procedure
◼X PC + 1; PC X + 1
Top of stack
Nested Procedure Calls
36
start
address how does
of Proc1 machine
know
where
to go
back
start to?
address
of Proc2 STACK!
Addressing Modes
37
Notations:
A = Contents of an address field in the instruction
R = Contents of an address field in the instruction that refers to a register
(X) = Contents of memory location X or register X
EA =Effective address of the location containing the referenced operand
Addressing Modes…
38
Direct
Indirect
Register
RegisterIndirect
Displacement
Immediate Addressing
39
Instruction
Opcode Operand
Direct Addressing
41
Instruction
Opcode A
Memory
Operand
Indirect Addressing
43
EA = (A)
Operand = ((A))
E.g. ADD (A)
◼ Look in A, find address (A) and look there for operand
Indirect Addressing …
44
Instruction
Opcode Address A
Memory
Pointer to operand
Operand
Register Addressing
46
No memory access
Very fast execution
Very limited address space
Register Addressing Diagram
48
Instruction
Operand
Register Indirect Addressing
49
Opcode R
Memory
Registers
Operand
Displacement Addressing
51
Instruction
Opcode R A
Memory
Registers
+ Operand
Relative Addressing
53
Saves bits
Base-Register Addressing
54
Combinations
Indirect addressing with indexing
Post indexing
The indexing performed after the indirection
EA = (A) + (R)
Good to access a block of data of a fixed format
Pre indexing
The indexing performed before the indirection
EA = (A+(R))
Used to construct a multiway branch table
Instruction Format
57
Processor Organization
Register Organization
◼ User-visibleregister
◼ Control and status registers
Instruction Cycle
Data Flow
Processor Organization
59
Registers
CPU must have some working space
◼ Temporary storage
Toplevel of memory hierarchy
Number and function vary between processor designs
Address registers
Condition codes
User Visible Registers
66
May be restricted
Data Registers
Used only to hold data
◼ Accumulator
User Visible Registers…
67
Address registers
Can be
◼ General purpose
◼ Devoted to particular addressing mode
◼ Index registers, stack pointer, segment register
Design Consideration
68
General or Specialized ?
Fewer registers
Results in more memory references
More registers
Does not noticeably reduce memory references
How big?
Address registers
Large enough to hold full address
Data Registers
Large enough to hold full word
Often possible to combine two data registers
Condition Codes
71
Basic Function
Execution of a program --- a set of instructions
Execute
Fetch Cycle
Program Counter (PC) holds address of next
instruction to be fetched
Processor fetches instruction from memory location
pointed by PC
Increment PC
Unless told otherwise
Instruction loaded into Instruction Register (IR)
78
Execute Cycle
Processor interprets instruction and performs required
actions
Processor-memory
◼ data transfer between CPU and main memory
Processor -I/O
◼ Data transfer between CPU and I/O module
Data processing
◼ Some arithmetic or logical operation on data
Control
◼ Alteration of sequence of operations
◼ e.g. jump
Combination of above
Example of Program Execution
80
Execute
Interrupt
Indirect addressing
May require memory access to fetch operands
Indirect addressing requires more memory accesses
Fetch
PC contains address of next instruction
Address moved to MAR
Address placed on address bus
Control unit requests memory read
Result placed on data bus, copied to MBR, then to IR
Meanwhile PC incremented by 1
Data Flow (Data Fetch)
96
IR is examined
If indirect addressing, indirect cycle is performed
Right most N bits of MBR transferred to MAR
Control unit requests memory read
Register transfers
ALU operations
Data Flow (Interrupt)
100
Simple
Predictable
Current PC saved to allow resumption after interrupt
Contents of PC copied to MBR
Special memory location (e.g. stack pointer) loaded to
MAR
MBR written to memory
PC loaded with address of interrupt handling routine
Next instruction (first of interrupt handler) can be
fetched
Data Flow (Interrupt Diagram)
101
Prefetch
Fetch accessing main memory
Execution usually does not access main memory
Can fetch next instruction during execution of
current instruction
Called instruction prefetch
103
The ALU
The ALU is the part of the microprocessor that
actually performs the arithmetic and logical
operations on data.
The rest of the circuitry simply
brings the data into the ALU,
tells the ALU what to do with it, and
Control Flags
Unit ALU
Registers Registers
The ALU
Registers are used to:
Bring data into the ALU
Store the results of the ALU’s operations
Registers
Control
Unit
ALU
Control Unit Design
Hardwired Control
The control logic is implemented using flip flops, gates, etc
The unit is designed specifically for the digital system being
designed
Modifying it is very tedious
Microprogrammed Control
The control information is stored in a Micro-memory inside
the CPU
The Microprogram memory is loaded with the sequence of
control signals needed to implement the different instructions
The Control Unit
The system clock produces a continuous sequence of pulses in a specified
duration and frequency. A sequence of steps t0 , t1 , t2 , . . . , (t0< t1 < t2 . . .)
are used to execute a certain instruction.
The op-code field of a fetched instruction is decoded to provide the control
signal generator with information about the instruction to be executed.