4th Unit COA
4th Unit COA
ORGANIZATION
&
ARCHITECTURE
Unit-
4
Central Processing Unit
2
Central Processing Unit
1. Introduction
2. General Register Organization
3. Stack Organization
4. Instruction Formats
5. Addressing Modes
6. Data Transfer and Manipulation
7. Program Control
8. Reduced Instruction Set Computer(RISC)
3
Central Processing Unit
• Register sets
a) Single Accumulator organization (Special purpose reg)
b) General Register Organization
c) Stack Organization
MAJOR COMPONENTS OF CPU
• Storage Components
Registers
Flags
• Transfer Components
Bus
• Control Components
Control Unit Register
File ALU
Control Unit
In general, most processors are organized in one of 3 ways
3. Stack organization
• All operations are done using the hardware stack
• For example, an OR instruction will pop the two top elements from the stack, do a
logical OR on them, and push the result on the stack
• In a Single Accumulator Organization there are few special purpose
registers
• In any CPU the total registers can be divided into different groups
i) General purpose registers ii) Special purpose registers
1. PC – Program Counter R1
2. AR – Address Register .
3. IR – Instruction Register .
4. DR – Data Register .
5. AC – Accumulator .
6. TR – Temporary Register .
7. INRR – Input Register .
8. OUPR – Output Register .
Rn
Control word
A general organization of seven CPU
registers
Consider R1 ← R2 + R3, the following are the
functions implemented within the CPU
Control word
A Stack Machine LIFO : Last In First Out
10
REGISTER STACK ORGANIZATION
A register stack is a memory space that uses memory words or registers
to store temporary information during program execution.
Stack
- Very useful feature for nested subroutines, nested interrupt services
- Also efficient for arithmetic expression evaluation
- Storage which can be accessed in LIFO
64 Word Stack
- Pointer: SP (stack Pointer)
- Only PUSH and POP operations are applicable
Register Stack
stack Address
Push, Pop operations 63
Flags
/* Initially, SP = 0, EMPTY = 1, FULL = 0 */ FULL EMPTY
Stack pointer
PUSH POP 4
SP C 3
SP SP + 1 DR M[SP]
6 bits B 2
M[SP] DR SP SP 1 A 1
If (SP = 0) then (FULL 1) If (SP = 0) then (EMPTY 1) 0
EMPTY 0 FULL 0 DR
MEMORY STACK ORGANIZATION RAM
A portion of memory is assigned to a stack operation to implement
the stack in the CPU.
1000
Program
Memory with Program, Data, and Stack Segments PC (instructions)
3000
SP
- PUSH: SP SP - 1 - POP: DR M[SP] stack
M[SP] DR SP SP + 1
3997
3998
Program Counter (PC): It is a register that points to the address of the next instruction that 3999
4000
is going to be executed in the program.
4001
Address Register (AR): This register points at the collection of data and is used during the Stack grows
In this direction
execute phase to read an operand.
Stack Pointer (SP): It points at the top of the stack and is used to push or pop the data items
in or from the stack.
• In-fix expression (X + Y)
• Pre-fix or polish notation ( +XY )
• Post fix expression or reverse polish notation (XY +)
Evaluation of Expressions
(a + b * c) / (a + d * c - e)
push a
/
push b
+ - multiply
a + e c push c
*
*
b c bb
*c
a *
a
d
c
Evaluation Stack
Reverse Polish
abc*+adc*+e-/
REVERSE POLISH NOTATION
• Arithmetic Expressions: A + B
(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(es) or a processor register(s)
Mode field - determines how the address field is to be interpreted (to
get effective address or the operand)
Program to evaluate X = (A + B) * (C + D) :
ADD R1, A, B /* R1 M[A] + M[B] */
ADD R2, C, D /* R2 M[C] + M[D] */
MUL X, R1, R2 /* M[X] R1 * R2 */
• Two-Address Instructions
Program to evaluate X = (A + B) * (C + D) :
• Implied
• Immediate
• Direct
• Indirect
• Register
• Register Indirect
• Autoincrement or AutoDecrement
• Relative
• Indexed
• Base Register
An assembly language program instruction consists of two parts
Implied Addressing Mode
• 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]
- Examples from Basic Computer
CLA, CME, INP
Instruction
• e.g. ADD 5
• Add 5 to contents of accumulator Opcode Operand
• 5 is operand
Example: MOV AL, 35H (move the data 35H into AL register)
Direct Addressing
• e.g. ADD A
– Add contents of cell A to accumulator
– Look in memory at address A for operand
Direct Addressing Diagram
Instruction
Opcode Address A
Memory
Operand
• EA = (A)
– Look in A, find address (A) and look there for operand
• e.g. ADD (A)
– Add contents of cell pointed to by contents of A to accumulator
Indirect Addressing Diagram
Instruction
Opcode Address A
Memory
Pointer to operand
Operand
Register Addressing
• 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)
• EA = R
Register Addressing Diagram
Instruction
Opcode Register Address R Registers
Operand
Register Indirect Addressing
• EA = (R)
Register Indirect Addressing Diagram
Instruction
Opcode Register Address R
Memory
Registers
Instruction
Opcode Register R Address A
Memory
Registers
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