Coa 6
Coa 6
Branch : - CSE
Computer Organization & Architecture (CSPC- 208 &
CSMI-202)
Lecture – 6
Central Processing Unit
Presenter – Dr. D. K. Meena
CENTRAL PROCESSING UNIT
Introduction
Stack Organization
Instruction Formats
Addressing Modes
Program Control
2
CENTRAL PROCESSING UNIT
A Central Processing Unit is also called a processor, central processor, or
microprocessor.
It carries out all the important functions of a computer.
It receives instructions from both the hardware and active software and
produces output accordingly.
It stores all important programs like operating systems and application
software.
CPU also helps Input and output devices to communicate with each
other. Owing to these features of CPU, it is often referred to as the brain
of the computer.
CPU is installed or inserted into a CPU socket located on the motherboard.
CPU is provided with a heat sink to absorb and dissipate heat to keep the
CPU cool and functioning smoothly.
CENTRAL PROCESSING UNIT
Generally, a CPU has three components:
1. ALU (Arithmetic Logic Unit)
2. Control Unit
3. Memory or Storage Unit
CENTRAL PROCESSING UNIT
Control Unit: It is the circuitry in the control unit, which makes use
of electrical signals to instruct the computer system for executing
already stored instructions.
It takes instructions from memory and then decodes and executes
these instructions.
So, it controls and coordinates the functioning of all parts of the
computer.
The Control Unit's main task is to maintain and regulate the flow of
information across the processor.
It does not take part in processing and storing data.
CENTRAL PROCESSING UNIT
ALU (Arithmetic Logic Unit) : It is the arithmetic logic unit, which
performs arithmetic and logical functions.
Arithmetic functions include addition, subtraction, multiplication
division, and comparisons.
Logical functions mainly include selecting, comparing, and merging
the data.
A CPU may contain more than one ALU.
Furthermore, ALUs can be used for maintaining timers that help run
the computer.
CENTRAL PROCESSING UNIT
Memory or Storage Unit/ Registers: It is called Random access
memory (RAM).
It temporarily stores data, programs, and intermediate and final
results of processing.
So, it acts as a temporary storage area that holds the data
temporarily, which is used to run the computer.
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
OPERATION OF CONTROL UNIT
The control unit directs the information flow through ALU by:
- Selecting various Components in the system
- Selecting the Function of ALU
Example: R1 <- R2 + R3
FULL EMPTY
Stack pointer 4
SP C 3
B 2
A 1
Push, Pop operations 0
DR
/* Initially, SP = 0, EMPTY = 1, FULL = 0 */
PUSH POP
SP ← SP + 1 DR ← M[SP]
M[SP] ← DR SP ← SP - 1
If (SP = 0) then (FULL ← 1) If (SP = 0) then (EMPTY ←
1)
cpe 252: Computer Organization 11
EMPTY ← 0 FULL ← 0
MEMORY STACK ORGANIZATION
Memory with Program, Data and Stack Segments 1000
Program
PC (instructions)
Data
AR (operands)
SP 3000
stack
A portion of memory is used as a stack with a processor
3997
register as a stack pointer 3998
3999
4000
PUSH: SP ← SP - 1 4001
M[SP] ← DR
DR
POP: DR ← M[SP]
SP ← SP + 1
12
REVERSE POLISH NOTATION
Arithmetic Expressions: A + B
A+B Infix notation
+AB Prefix or Polish notation
AB+ Postfix or reverse Polish notation
The reverse Polish notation is very suitable for stack manipulation
(3 * 4) + (5 * 6) ⇒ 34*56*+
6
4 5 5 30
3 3 12 12 12 12 42
3 4 * 5 6 * +
INSTRUCTION FORMAT
Instruction Fields
OP-code field - specifies the operation to be performed
Address field - designates memory address(s) or a processor register(s)
Mode field - specifies the way the operand or the effective address is
determined
The number of address fields in the instruction format depends on the
internal organization of CPU
The three most common CPU organizations:
Single accumulator organization:
ADD X /* AC ← AC + M[X] */
General register organization:
ADD R1, R2, R3 /* R1 ← R2 + R3 */
ADD R1, R2 /* R1 ← R1 + R2 */
MOV R1, R2 /* R1 ← R2 */
ADD R1, X /* R1 ← R1 + M[X] */
Stack organization:
PUSH X /* TOS ← M[X] */
ADD
THREE, and TWO-ADDRESS INSTRUCTIONS
Three-Address Instructions:
Program to evaluate X = (A + B) * (C + D) :
ADDR1, A, B /* R1 M[A] + M[B] */
ADDR2, C, D /* R2 M[C] + M[D] */
MULX, R1, R2 /* M[X] R1 * R2 */
Two-Address Instructions:
Program to evaluate X = (A + B) * (C + D) :
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
Address specified in the instruction is the register address
✔Designated operand need to be in a register
✔Shorter address than the memory address
✔Saving address field in the instruction
✔Faster to acquire an operand than the memory addressing
✔EA = IR(R) (IR(R): Register field of IR)
TYPES OF ADDRESSING MODES
Register Indirect Mode
Instruction specifies a register which contains the memory address of
the operand
Saving instruction bits since register address is shorter than the
memory address
Slower to acquire an operand than both the register addressing or
memory addressing
EA = [IR(R)] ([x]: Content of x)
Auto-increment or Auto-decrement features:
Same as the Register Indirect, but: When the address in the register is
used to access memory, the value in the register is incremented or
decremented by 1 (after or before the execution of the instruction)
TYPES OF ADDRESSING MODES
Direct Address Mode
Instruction specifies the memory address which can be used directly to
the physical memory
✔ Faster than the other memory addressing modes
✔ Too many bits are needed to specify the address for a large physical
memory space
✔ EA = IR(address), (IR(address): address field of IR)
Indirect Addressing Mode
The address field of an instruction specifies the address of a memory
location that contains the address of the operand
✔ When the abbreviated address is used, large physical memory can
be addressed with a relatively small number of bits
✔ Slow to acquire an operand because of an additional memory
access
- EA = M[IR(address)]
TYPES OF ADDRESSING MODES
Relative Addressing Modes
The Address fields of an instruction specifies the part of the address
(abbreviated address) which can be used along with a designated
register to calculate the address of the operand
PC Relative Addressing Mode(R = PC)
- EA = PC + IR(address)
Address field of the instruction is short
Large physical memory can be accessed with a small number of address
bits
Indexed Addressing Mode
XR: Index Register:
- EA = XR + IR(address)
Base Register Addressing Mode
BAR: Base Address Register:
- EA = BAR + IR(address)
ADDRESSING MODES - EXAMPLES
In relative address mode the value in PC after
fetch phase and during the execute phase is Address Memory
202 200 Load to AC Mode
PC = 200 201 Address = 500
202 Next instruction
R1 = 400
399 450
XR = 100
400 700
AC
500 800
600 900
Addressing Effective Content
Mode Address of AC
Direct address 500 /* AC ← (500) */ 800 702 325
Immediate operand - /* AC ← 500 */ 500
Indirect address 800 /* AC ← ((500)) */ 300
Relative address 702 /* AC ← (PC+500) */ 800 300
325
Indexed address 600 /* AC ← (XR+500) */
900
Register - /* AC ← R1 */ 400
Register indirect 400 /* AC ← (R1) */ 700
Autoincrement400 /* AC ← (R1)+ */ 700
Autodecrement 399 /* AC ← -(R) */ 450
Data Transfer and Manipulation
Computer instruction are classified in to three category:-
1. Data transfer instructions Data Transfer Instructions
2. Data manipulation instructions Name Mnemonic
3. Program control instructions Load LD
Store ST
Move MOV
Exchange XCH
Input IN
Output OUT
Push PUSH
Pop POP
Data Transfer Instructions with Different Addressing Modes
Assembly
Mode Convention Register Transfer
Direct address LD ADR AC M[ADR]
Indirect address LD @ADR AC M[M[ADR]]
Relative address LD $ADR AC M[PC + ADR]
Immediate operand LD #NBR AC NBR
Index addressing LD ADR(X) AC M[ADR + XR]
Register LD R1 AC R1
Register indirect LD (R1) AC M[R1]
Autoincrement LD (R1)+ AC M[R1], R1 R1 + 1
Autodecrement LD -(R1) R1 R1 - 1, AC
M[R1]
DATA MANIPULATION INSTRUCTIONS
Three Basic Types: Arithmetic instructions
Logical and bit manipulation instructions
Shift instructions
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
Characteristic of CISC –
Complex instruction, hence complex instruction decoding.
Instructions are larger than one-word size.
Instruction may take more than a single clock cycle to get executed.
Less number of general-purpose registers as operations get performed
in memory itself.
Complex Addressing Modes.
More Data types.
Difference between RISC and CISC
RISC CISC
Focus on software Focus on hardware
Can perform only Register to Register Can perform REG to REG or REG to MEM
Arithmetic operations or MEM to MEM
An instruction executed in a single clock Instruction takes more than one clock
cycle cycle