chapter7 cpu
TRANSCRIPT
-
8/3/2019 Chapter7 CPU
1/56
Computer Organization
and Architecture
Chapter 7
Central Processing Unit (CPU)
-
8/3/2019 Chapter7 CPU
2/56
Central Processing Unit (CPU)
CPU structure and function
Instruction Sets: Characteristics
and Functions
Instruction Sets: Addressing Modes
and Formats
-
8/3/2019 Chapter7 CPU
3/56
CPU structure and function
-
8/3/2019 Chapter7 CPU
4/56
CPU Structure
CPU must:
Fetch instructions CPU reads an instruction frommemory
Interpret instructions instruction is decoded todetermine what action is required
Fetch data execution instruction may requirereading data from memory or I/O module
Process data execution instruction may requiredoing arithmetic or logical operation on data
Write data result of instruction may writing data tomemory or I/O module
-
8/3/2019 Chapter7 CPU
5/56
CPU Organization
-
8/3/2019 Chapter7 CPU
6/56
-The major components of the CPU are arithmeticand logic unit (ALU), Control Unit (CU) and
registers.
-The ALU does the actual computing or processingthe data
-The control unit controls the movement of data and
instructions into and out of the CPU and control theoperation of ALU.
-Registers is a small storage location in the CPU.
CPU Organization cont
-
8/3/2019 Chapter7 CPU
7/56
CPU Internal Structure
-
8/3/2019 Chapter7 CPU
8/56
Registers
CPU must have some working space (temporary
storage) Called registers
Number and function vary between processor designs
One of the major design decisions
Top level of memory hierarchy
General roles are performed by CPU register:
User-visible register-Enable assembly-language
programmer to minimize main memory references byoptimizing use of registers.
Control and status registers- Used by the control unit tocontrol the operation of CPU and to control the execution ofprograms.
-
8/3/2019 Chapter7 CPU
9/56
User Visible Registers
General Purpose
Data
Address
Condition Codes
General purpose-can be assigned to a variety of functions by theprogrammer. Can contain the operand for any opcode.
Data register-used only to hold data.
Address register-this register only hold address information.Condition codes-values set by the CPU as the result of performingoperations. Example code bits: zero, positive, negative
-
8/3/2019 Chapter7 CPU
10/56
Control & Status Registers
Four register essential to instruction execution (control themovement of data between CPU and memory):
Program counter (PC)contains the address of an instruction
to be fetched
Instruction register (IR)
Contains the instruction most
recently fetched
Memory address register (MAR) Contains the address of a
location in memory.
Memory buffer register (MBR) Contains a word of data to be
written to memory or the word most recently read.
-
8/3/2019 Chapter7 CPU
11/56
All CPU design include a register or a set of registers known as
Program Status Word (PSW), that contain status information Common fields or flags for PSW:
Sign -contain the sign bit of the result of the last arithmeticoperation.
Zero -set when the result is 0.
Carry -set if an operation resulted in a carry (addition) into orborrow (subtraction) out of a high-order bit.
Equal -set if a logical compare result is equality
Overflow -Used to indicate arithmetic overflow
Interrupt enable/disable -used to enable or disable interrupts
Supervisor -Indicates whether the CPU is executing in supervisoror user mode. Certain privileged instructions can be executed onlyin supervisor mode, and certain areas of memory can be accessedonly in supervisor mode.
Control & Status Registers cont.
-
8/3/2019 Chapter7 CPU
12/56
Example Register Organizations
-
8/3/2019 Chapter7 CPU
13/56
Instruction Sets:
Characteristics and Functions
-
8/3/2019 Chapter7 CPU
14/56
What is an instruction set?
The complete collection of instructions that are
understood by a CPU
Machine Code
Binary
Usually represented by assembly codes
-
8/3/2019 Chapter7 CPU
15/56
Elements of an Instruction
Operation code (Op code)
Do this
Source Operand reference
To this
Result Operand referencePut the answer here
Next Instruction Reference
When you have done that, do this...
-
8/3/2019 Chapter7 CPU
16/56
Where have all the Operands gone?
The location for the source and destination for
the operand can be in one of three areas:
-Main memory (or virtual memory or cache)
-CPU register-I/O device
-
8/3/2019 Chapter7 CPU
17/56
Instruction Cycle State Diagram
-
8/3/2019 Chapter7 CPU
18/56
Instruction Representation
In machine code each instruction has a unique
bit pattern
For human consumption (well, programmersanyway) a symbolic representation is used
e.g. ADD, SUB, LOAD Operands can also be represented in this way
ADD A,B
-
8/3/2019 Chapter7 CPU
19/56
Simple Instruction Format
-
8/3/2019 Chapter7 CPU
20/56
Instruction Types
Data processing
Data storage (main memory)
Data movement (I/O)
Program flow control
-
8/3/2019 Chapter7 CPU
21/56
Number of Addresses (a)
3 addresses
Operand 1, Operand 2, Result
a = b + c;
May be a forth - next instruction (usually implicit)
Not commonNeeds very long words to hold everything
-
8/3/2019 Chapter7 CPU
22/56
Number of Addresses (b)
2 addresses
One address doubles as operand and result
a = a + b
Reduces length of instruction
Requires some extra work Temporary storage to hold some results
-
8/3/2019 Chapter7 CPU
23/56
Number of Addresses (c)
1 address
Implicit second address
Usually a register (accumulator)
Common on early machines
-
8/3/2019 Chapter7 CPU
24/56
Number of Addresses (d)
0 (zero) addresses
All addresses implicit
Uses a stack
e.g. push a
push b add
pop c
c = a + b
-
8/3/2019 Chapter7 CPU
25/56
How Many Addresses
More addresses
More complex (powerful?) instructions
More registers
Inter-register operations are quicker
Fewer instructions per program
Fewer addresses
Less complex (powerful?) instructions
More instructions per program
Faster fetch/execution of instructions
-
8/3/2019 Chapter7 CPU
26/56
Types of Operand
Addresses
Numbers
Integer/floating point
Characters
ASCII etc.
Logical Data
Bits or flags
-
8/3/2019 Chapter7 CPU
27/56
Types of Operation
Data Transfer
Arithmetic
Logical
Conversion
I/O
System Control
Transfer of Control
-
8/3/2019 Chapter7 CPU
28/56
Data Transfer
Specify
Source
Destination
Amount of data
May be different instructions for differentmovements
e.g. IBM 370
Or one instruction and different addresses
e.g. VAX
-
8/3/2019 Chapter7 CPU
29/56
Arithmetic
Add, Subtract, Multiply, Divide
Signed Integer
Floating point ?
May include
Increment (a++)
Decrement (a--)
Negate (-a)
-
8/3/2019 Chapter7 CPU
30/56
Shift and Rotate Operations
-
8/3/2019 Chapter7 CPU
31/56
Logical
Bitwise operations
AND, OR, NOT
-
8/3/2019 Chapter7 CPU
32/56
Conversion
E.g. Binary to Decimal
-
8/3/2019 Chapter7 CPU
33/56
Input/Output
May be specific instructions
May be done using data movement instructions(memory mapped)
May be done by a separate controller (DMA)
-
8/3/2019 Chapter7 CPU
34/56
Systems Control
Privileged instructions
CPU needs to be in specific state
Ring 0 on 80386+
Kernel mode
For operating systems use
-
8/3/2019 Chapter7 CPU
35/56
Transfer of Control
Branch
e.g. branch to x if result is zero
Skip
e.g. increment and skip if zero
ISZ Register1Branch xxxx
ADD A
Subroutine call
c.f. interrupt call
-
8/3/2019 Chapter7 CPU
36/56
Branch Instruction
-
8/3/2019 Chapter7 CPU
37/56
Instruction Sets: Addressing Modes
and Formats
-
8/3/2019 Chapter7 CPU
38/56
Addressing Modes
Immediate
Direct
Indirect
Register
Register Indirect
Displacement (Indexed)
Stack
-
8/3/2019 Chapter7 CPU
39/56
Immediate Addressing
Operand is part of instruction
Operand = address field
e.g. ADD 5
Add 5 to contents of accumulator
5 is operand No memory reference to fetch data
Fast
Limited range
-
8/3/2019 Chapter7 CPU
40/56
Immediate Addressing Diagram
OperandOpcode
Instruction
-
8/3/2019 Chapter7 CPU
41/56
Direct Addressing
Address field contains address of operand
Effective address (EA) = address field (A)
e.g. ADD A
Add contents of cell A to accumulator
Look in memory at address A for operand Single memory reference to access data
No additional calculations to work out effectiveaddress
Limited address space
-
8/3/2019 Chapter7 CPU
42/56
Direct Addressing Diagram
Address AOpcode
Instruction
Memory
Operand
-
8/3/2019 Chapter7 CPU
43/56
Indirect Addressing (1)
Memory cell pointed to by address field contains
the address of (pointer to) the operand
EA = (A)
Look in A, find address (A) and look there foroperand
e.g. ADD (A)
Add contents of cell pointed to by contents of A toaccumulator
-
8/3/2019 Chapter7 CPU
44/56
Indirect Addressing (2)
Large address space
2n where n = word length
May be nested, multilevel, cascaded
e.g. EA = (((A)))
Draw the diagram yourself
Multiple memory accesses to find operand
Hence slower
-
8/3/2019 Chapter7 CPU
45/56
Indirect Addressing Diagram
Address AOpcodeInstruction
Memory
Operand
Pointer to operand
-
8/3/2019 Chapter7 CPU
46/56
Register Addressing (1)
Operand is held in register named in address
filed
EA = R
Limited number of registers
Very small address field neededShorter instructions
Faster instruction fetch
-
8/3/2019 Chapter7 CPU
47/56
Register Addressing (2)
No memory access
Very fast execution
Very limited address space
Multiple registers helps performance
Requires good assembly programming or compilerwriting
Likes C programming
register int a;
Same with Direct addressing
-
8/3/2019 Chapter7 CPU
48/56
Register Addressing Diagram
Register Address ROpcode
Instruction
Registers
Operand
-
8/3/2019 Chapter7 CPU
49/56
Register Indirect Addressing
EA = (R)
Operand is in memory cell pointed to bycontents of register R
Large address space (2n)
One fewer memory access than indirectaddressing
-
8/3/2019 Chapter7 CPU
50/56
Register Indirect Addressing Diagram
Register Address ROpcode
Instruction
Memory
OperandPointer to Operand
Registers
-
8/3/2019 Chapter7 CPU
51/56
Displacement Addressing
EA = A + (R)
Address field hold two values
A = base value
R = register that holds displacement
or vice versa
-
8/3/2019 Chapter7 CPU
52/56
Displacement Addressing Diagram
Register ROpcode
Instruction
Memory
OperandPointer to Operand
Registers
Address A
+
-
8/3/2019 Chapter7 CPU
53/56
Relative Addressing
A version of displacement addressing
R = Program counter, PC
EA = A + (PC)
i.e. get operand from A cells from current
location pointed to by PC locality of reference & cache usage
-
8/3/2019 Chapter7 CPU
54/56
Indexed Addressing
A = base
R = displacement
EA = A + R
Good for accessing arrays
EA = A + RR++
-
8/3/2019 Chapter7 CPU
55/56
Stack Addressing
Operand is (implicitly) on top of stack
e.g.
ADD Pop top two items from stackand add
-
8/3/2019 Chapter7 CPU
56/56
Stack Addressing
Top of stack register
Implicit
Instruction