Chapter 4 Processor - 2014
Chapter 4 Processor - 2014
Chapter 4 Processor - 2014
• Introduction
• General Register Organization
• Stack Organization
• Instruction Formats
• Addressing Modes
• Data Transfer and Manipulation
cpe 252: Computer Organization 2
• Program Control
4.1 Introduction
2. Memory
3. Input Unit
4. Output Unit
3
• The computer’s CPU fetches, decodes, and
executes program instructions.
• The two principal parts of the CPU are the datapath
and the control unit.
– The datapath consists of an arithmetic-logic unit and
storage units (registers) that are interconnected by a data
bus that is also connected to main memory.
– Various CPU components perform sequenced operations
according to signals provided by its control unit.
4
Major Components
• ALU (arithmetic logic unit): Performs calculations and comparisons (data changed)
• CU (control unit): The control unit determines which actions to carry out according to the
values in a program counter register and a status register.
– performs fetch/execute cycle
– Functions:
• Moves data to and from CPU registers and other hardware components (no change in data)
• Accesses program instructions and issues commands to the ALU
– Subparts:
• Memory management unit: supervises fetching instructions and data
• I/O Interface: sometimes combined with memory management unit as Bust Interface Unit
• Registers
– Registers hold data that can be readily accessed by the CPU.
– They can be implemented using D flip-flops.
– A 32-bit register requires 32 D flip-flops.
– Example: Program counter (PC) or instruction pointer determines next instruction for
execution
5
6
Registers
• Small, permanent storage locations within the CPU used for a
particular purpose
– Scratchpad for currently executing program
• Holds data needed quickly or frequently
– Stores information about status of CPU and currently executing program
• Address of next program instruction
• Signals from external devices
• Manipulated directly by the Control Unit
• Wired for specific function
• Size in bits or bytes (not MB like memory)
• Can hold data, an address or an instruction
7
Types of Registers
• User visible registers
– A user visible register is simply a register than can be referenced
with the machine language of the processor •
– Four categories
• General Purpose
• Data
• Address
• Condition Codes
• Control and Status Registers
8
General Purpose
10
• Special purpose Registers
– Program Count Register (PC)
• Also called instruction pointer
– Instruction Register (IR)
• Stores instruction fetched from memory
– Memory Address Register (MAR)
– Memory Data Register (MDR)
– Status Registers
• Status of CPU and currently executing program
• Flags (one bit Boolean variable) to track condition like
arithmetic carry and overflow, power failure, internal
computer
11
CPU Register Lengths
• The register lengths (number of flip-flops to store bits) are determined by
number of memory locations (address space) and the bus width (in bits)
that determines the number of bits transferred between Memory and
CPU, or between I/O channels and CPU.
PC
12 bits
AR
16 bits
DR
IR
AC
8 bits
INR
4 bits
OUTR
1 bit
SCR
1 bit
R
GENERAL REGISTER
ORGANIZATION
Input
Clock
R1
R2
R3
R4
R5
R6
R7
Load
(7 lines)
SELA { MUX MUX } SELB
3x8
A bus B bus
decoder
SELD
OPR ALU
Output
14
Operation of Memory
16
Control Unit
• It is responsible for directing and coordinating
most of the computer system activities.
• It does not execute instructions by itself. It tells
other parts of the computer system what to do.
• It determines the movement of electronic signals
between the main memory and arithmetic logic
unit as well as the control signals between the
CPU and input/output devices.
Control Unit(Condt…)
• To complete an event i.e. processing, control
unit repeats a set of four basic operations:
– Fetching is the process of obtaining a program
instruction or data item from the memory
– Decoding is the process of translating the instruction
into commands the computer can execute.
– Executing is the process of carrying out the
commands.
– Storing is the process of writing the result to
memory.
Control Unit(Condt…)
• The internal communication inside a computer that
transforms raw data into useful information is called
processing.
• To perform this transformation, the computer uses two
components- processor and memory
• The program is fed into the computer through the input unit
and stored in the memory
• To execute the program, the instructions have to be fetched
from memory one by one which is done by control unit
• Then the control unit decodes the instruction.
Control Unit(Condt…)
• According to instruction, control unit issues
signals to other units.
• After instruction is executed, the result of the
instruction is stored in memory or stored
temporarily in the registry, so that this can be
used by the next instruction.
• The results of a program are taken out of the
computer through the output unit.
OPERATION OF CONTROL UNIT
The control unit directs the information flow through ALU by:
ALU CONTROL
Examples of ALU Microoperations Microoperation SELA SELB SELD OPR Control Word
2 a
1 c
3 b
r1 2
r2
r3
Logic Memory
r4
2 a
1 c
3 b
r1 2
r2
r3 3
Logic Memory
r4
2 a
1 c
3 b
r1 2
r2 5
r3 3
Logic Memory
r4
2 a
1 c
3 b
r1 2
r2 5
r3 3
Logic Memory
r4
2 a
5 c
3 b
r1 2
r2 5
r3 3
Logic Memory
r4
r2 r1 + r3
Store r2 into c
• E.g. 1101101000001110011
Machine/Assembly Language
• Basic Questions:
• What instructions?
• Instruction
– Direction given to a computer
– Causes electrical signals to be sent through specific circuits for
processing
addressing mode there are two memory accesses, but only one reference.
1
15 14 12 11 0
IR
Mode bit I OpCode Address
Instructions set Design
• Instruction set
– Design defines functions performed by the processor
– Differentiates computer architecture by the
• Number of instructions
• Complexity of operations performed by individual instructions
• Data types supported
• Format (layout, fixed vs. variable length)
• Use of registers
• Addressing (size, modes)
IR
I OpCode Address
Instruction Hierarchy
• It is desirable to engineer the computer to support a
reasonable number of independent instructions
– Use a hierarchical scheme (1+3 scheme)
• OpCode – 3 bits – supports 8 unique codes
– 0-6 (instructions)
– 7 (toggle)
• Mode – 1 bit – supports 2 addressing modes
– I=0 Direct addressing
– I=1 Indirect addressing
• Special Case :: OpCode = 7 (toggle) PLUS Mode bit (I)
– Use 12 bits of Address field to specify additional instructions
15 14 12 11 0
IR
I OpCode Address
Instruction Hierarchy
• Mano’s instruction set consists of 25 instructions:
Instruction
7008 SNA
Instruction Set Completeness
• Selection of instructions should span a variety of applications
suitable to support programming
An important issue for many applications is the number of programmable (general purpose)
registers.
– Arithmetic,
Mano adoptslogical and providing
a minimalist approach shift ainstructions
single such register, the accumulator AC.
This simple case does allow full illustration of all computational requirements of a more
powerful computer with a larger instruction set (but with much added cost to programming).
– Instructions for moving data to and from memory and CPU
Among commercial computers one finds both complex (large number) instruction sets (CISC)
registers
and reduced (number) instruction sets (RISC).
CLR
SC INC
– Each instruction will require a specified number of time steps to complete a
sequence of microoperations.…… Each step of the sequence is marked by a count
value in SC.
Timing and Control
• The SC outputs a string of bits whose value is in the range from
0 to 2L-1
– Eg. for L=3, from 0 to 7
• We need a way of converting the bit string value to single bit
valued outputs labelled T0, T1, T2, T3, and so on, up to Tx
(where x = 2L-1)
• A decoder serves our purpose, recalling that the output from the
DEC is a 1 only on one line (the rest are 0`s)
Tx T2 T1 T0
CLR
…..
SC INC
L-to-2L DEC
……
…
Timing and Control
• Step 1: Where do we fetch the next instruction from
at T0 (start time)?
T0 : AR = PC Load
AR
Timing and Control
– The data
This restriction to
stored non-sequential instructionsDR
at the selected
M[AR] is removed by including instructions that
address isPCtransferred
LD
onto the
modify the PC explicitly.
Data Bus and then to the Data Register (DR) in the CPU.
– The instruction data is transferred IR
immediately to the
LD
T1 : DR = M[AR] , IR = DR , PC = PC + 1
• Direct addressing
complicated, requiring more inputs.
AR = IR(0-11),
F E D C B A 9 ... 1 0
Timing inputs
4x16 DEC
3 2 1 0
Clock has not
Counter (SC)
Instruction Format
INSTRUCTION FORMAT
Instruction Fields
ADD X /* AC AC + M[X] */
ADD R1, R2 /* R1 R1 + R2 */
MOV R1, R2 /* R1 R2 */
Stack organization:
PUSH X
cpe 252: Computer Organization
/* TOS M[X] */
50
ADD
THREE, and TWO-ADDRESS INSTRUCTIONS
Three-Address Instructions:
Program to evaluate X = (A + B) * (C + D) :
Two-Address Instructions:
Program to evaluate X = (A + B) * (C + D) :
LOAD A /* AC M[A] */
ADD B /* AC AC + M[B] */
STORE T /* M[T] AC */
LOAD C /* AC M[C] */
ONE, and ZERO-ADDRESS INSTRUCTIONS
ADD D /* AC AC + M[D] */
MUL T /* AC AC * M[T] */
- Can be found
STORE X in a stack-organized
/* M[X] AC computer
*/
Zero-Address Instructions:
- Program to evaluate X = (A + B) * (C + D) :
PUSHA /* TOS A */
PUSHB /* TOS B */
ADD /* TOS (A + B) */
PUSHC /* TOS C */
PUSHD /* TOS D */
ADD /* TOS (C + D) */
MUL /* TOS cpe
(C + 252:
D) * (AComputer
+ B) */ Organization 52
POP X /* M[X] TOS */
ADDRESSING MODES
Addressing Modes:
is actually referenced)
instruction efficiently
Implied Mode
Address of the operands are specified implicitly
in the definition of the instruction
- No need to specify address in the instruction
- EA = AC, or EA = Stack[SP], EA: Effective Address .
Immediate Mode
Instead of specifying the address of the operand,
operand itself is specified
- No need to specify address in the instruction
- However, operand itself needs to be specified
- Sometimes, require more bits than the address
- Fast to acquire an operand
Register Mode
cpe 252:
Address specified in the instruction Computer
is the Organization
register address 54
- Designated operand need to be in a register
TYPES OF ADDRESSING MODES
The Address fields of an instruction specifies the part of the address (abbreviated address) which can be used along
- EA = PC + IR(address)
Address Memory
R1 = 400
399 450
XR = 100
400 700
AC
500 800
Name Mnemonic
Load LD
Store ST
Move MOV
Exchange XCH
Input IN
Output OUT
Push PUSH
Pop POP
Assembly
Mode Register Transfer
Convention
Register LD R1 AC R1
Arithmetic Instructions
Name Mnemonic
Increment INC
Decrement DEC
Add ADD
Subtract SUB
Multiply MUL
Divide DIV
Add with Carry ADDC
Subtract with Borrow SUBB
Negate(2’s Complement) NEG
Enable interrupt EI
Disable interrupt DI
cpe 252: Computer Organization 60
PROGRAM CONTROL INSTRUCTIONS
+1
In-Line Sequencing
(Next instruction is fetched from the
PC next adjacent location in the memory)
Name Mnemonic
Branch BR
Jump JMP
Skip SKP
Call CALL
* CMP and TST instructions do not retain their
Return RTN
results of operations(- and AND, respectively).
Compare(by - ) CMP
They only set or clear certain Flags.
Test (by AND) TST
c
7
8-bit ALU
c
8 F -F
7 0
V Z S C
F
7
Check for 8
zero output
• In a processor Register
• In a memory stack RTN
- Power Failure
- Divide by zero
- OP-code Violation
- Protection Violation
Software Interrupts
Both External and Internal Interrupts are initiated by the computer Hardware.
- Supervisor Call -> Switching from a user mode to the supervisor mode
Content of the PC
Many ways of saving the CPU state depending on the CPU architectures
Compiler -program
High-Level Instruction
Hardware
Language Set
Architecture Implementation
Characteristics of CISC:
2. Some instructions that performs a certain tasks are not used frequently.
1-Cycle instruction
* Register-Register Instructions
- Avoid memory reference instructions except
Load and Store instructions
- Most of the operands can be found in the
registers instead of main memory
=> Shorter instructions
=> Uniform instruction cycle
=> Requirement of large number of registers
- Operations are register-to-register, with only LOAD and STORE accessing memory
Advantages of RISC
- VLSI Realization
- Computing Speed
71