Chapter 4 Cpu
Chapter 4 Cpu
Topics
Introduction
General Register Organization
Stack Organization
Instruction Formats
Addressing Modes
Data Transfer and Manipulation
Program Control
Reduced Instruction Set Computer
4-1 Introduction
3 major parts of CPU : Fig. 4-1
1) Register Set
2) ALU: microoperation
3) Control: supervise information transfer
The last section presents the concept of Reduced Instruction Set Computer (RISC)
4-2 General Register Organization
External Input
Register
C lo c k In p u t
Memory locations are needed for storing
pointers, counters, return address, temporary R1
Control Word
14 bit control word (4 fields) : Fig. 8-2(b)
» SELA (3 bits) : select a source register for the A input of the ALU
» SELB (3 bits) : select a source register for the B input of the ALU Tab. 8-1
» SELD (3 bits) : select a destination register using the 3 X 8 decoder
» OPR (5 bits) : select one of the operations in the ALU Tab. 8-2
Encoding of Register Selection Fields : Tab. 8-1
» SELA or SELB = 000 (Input) : MUX selects the external input data
» SELD = 000 (None) : no destination register is selected but the contents of the output
bus are available in the external output
Encoding of ALU Operation (OPR) : Tab. 8-2
Control Word Control Memory Micr
oprogrammed Control
Examples of Microoperations : Tab. 8-3
TSFA (Transfer A) : R 7 R1, External Output R 2, External Output External Input
XOR : R5 0 ( XOR R5 R5)
4-3 Stack Organization
Stack or LIFO(Last-In, First-Out)
A storage device that stores information
» The item stored last is the first item retrieved = a stack of tray
Stack Pointer (SP)
» The register that holds the address for the stack
» SP always points at the top item in the stack
Two Operations of a stack : Insertion and Deletion of Items
» PUSH : Push-Down = Insertion A d d re s s
PUSH : SP SP 1 : Increment SP A 1
Last Item 0
SP = 0, M [ SP ] DR : Write to the stack
EMTY = 1, If ( SP 0) then ( FULL 1) : Check if stack is full
FULL = 0 DR
EMTY 0 : Mark not empty
» The first item is stored at address 1, and the last item is stored at address 0
POP : DR M [ SP ] : Read item from the top of stack * Memory Stack
PUSH = Address
SP SP 1 : Decrement Stack Pointer * Register Stack
If ( SP 0) then ( EMTY 1) : Check if stack is empty PUSH = Address
PUSH : SP SP 1 P ro g ra m
( in s tr u c t io n s )
M [ SP ] DR
SP = 4001 2000
» The first item is stored at address 4000 AR
D a ta
POP : DR M [ SP ] (o p e ra n d s )
SP SP 1 * Error Condition
3000
PUSH when FULL = 1
S ta c k
Stack Limits POP when EMTY = 1
6
4 5 5 30
3 3 12 12 12 12 42
3 4 * 5 6 * +
X = Operand Address
3 types of CPU organizations
1) Single AC Org. : ADD X AC AC M [ X ]1 address filed
2) General Register Org. : ADD R1, R2, R3 R1 R 2 R 3 deepened on no of register
3) Stack Org. : PUSH X TOS M [ X ]no address field if the instruction is ADD/MUL
The influence of the number of addresses on computer instruction
X = (A + B)*(C + D) with zero, one, two or three address instructions
- 4 arithmetic operations : ADD, SUB, MUL, DIV
- 1 transfer operation to and from memory and general register : MOV
- 2 transfer operation to and from memory and AC register : STORE, LOAD
- Operand memory addresses : A, B, C, D
- Result memory address : X
1) Three-Address Instruction
ADD R1, A, B R1 M [ A] M [ B ]
ADD R2, C, D R 2 M [C ] M [ D ]
MUL X, R1, R2 M [ X ] R1 R 2
» Each address fields specify either a processor register or a memory operand
Short program to perform arithmetic operation.
» Require too many bit to specify 3 address
MOV R1, A R1 M [ A]
ADD R1, B R1 R1 M [ B ]
MOV R2, C R 2 M [C ]
ADD R2, D R2 R2 M [ D]
MUL R1, R2 R1 R1 R 2
MOV X, R1 M [ X ] R1
» The most common in commercial computers
» Each address fields specify either a processor register or a memory operand
3) One-Address Instruction
LOAD A AC M [ A]
ADD B AC A[C ] M [ B ]
STORE T M [T ] AC
LOAD C AC M [C ]
ADD D AC AC M [ D ]
MUL T AC AC M [T ]
STORE X M [ X ] AC
» All operations are done between the AC register and memory operand
4) Zero-Address Instruction
PUSH A TOS A
PUSH B TOS B
ADD TOS ( A B )
PUSH C TOS C
PUSH D TOS D
ADD TOS (C D )
MUL TOS (C D ) ( A B )
POP X M [ X ] TOS
» Stack-organized computer does not use an address field for the instructions ADD, and
MUL
» PUSH, and POP instructions need an address field to specify the operand
» Zero-Address : absence of address ( ADD, MUL )
4-5 Addressing Modes
What is the work of operation field and address field in the given instruction?
The addressing mode identifies the way operand is choose
Purpose of Addressing Mode
1) To give programming versatility to the user
Instruction Cycle
» Example : LD (R1)+
AC M [ R1], R1 R1 1
The value of address field may give the address of the operand or address which
helps to calculate the address of the operand
What is effective address?
Direct Addressing Mode
Effective address is equal to the address field of the instruction (Operand)
Address field specifies the actual branch address in a branch-type instruction
Example : LD ADR AC M [ ADR ]
ADR = Address part of Instruction
Indirect Addressing Mode
Address field of instruction gives the address where the effective address is
stored in memory
Example : LD @ADR AC M [ M [ ADR ]]
R1 = 400
600 900
500 + 202 (PC)
R1 = 400 (after) 702 325
500 + 100 (XR)
R1 = 400 -1 (prior)
800 300
4-6 Data Transfer and Manipulation
Most computer instructions can be classified into three categories:
1) Data transfer, 2) Data manipulation, 3) Program control instructions
Branch and Jump instructions are used interchangeably to mean the same thing,
but some times use d/t addressing modes.
• Conditional :some condition should met to change the program counter and cause
branch.
11110000
C = 1, S = 1, V = 0, Z = 0
+ 11101100 (2’s comp. of B)
A > B ,1A11011100
≠ B ( BHI, BHE or BNE)
Subroutine Call and Return: self-contained sequence of instruction
Have different names(jump or branch to subroutine, branch and save return address
When subroutine is called, branch is executed by doing two things
of an instruction
1) External Interrupts
» come from I/O device, from a timing device, from a circuit M a i n bmonitoring
o d y o f IS R
» 2) Some instructions that perform specialized tasks and are used infrequently
R32
( a ) R e g is t e r m o d e : ( S 2 s p e c if ie s a r e g is t e r )
Register Immediate Mode : bit 13 = 1
» S2 = sign extended 13 bit constant 31 24 23 19 18 14 13 12 0
Opcode Rd Rs 1 S2
» Example) LDL (R22)#150, R5
8 5 5 1 13
LDL (Rs)S2, Rd : Rd = M[R22] + 150
( b ) R e g is t e r - im m e d ia t e m o d e : ( S 2 s p e c if ie s a n o p e r a n d )
PC Relative Mode
31 24 23 19 18 0
» Y = 19 bit relative address
O pcode COND Y
» Example) JMPR COND, Y
8 5 19
Jump to PC = PC + Y
» CWP (Current Window Pointer) ( c ) P C r e la t iv e m o d e :
CALL, RET
RISC Architecture Originator
Architecture Originator Licensees
Alpha DEC Mitsubishi, Samsung
MIPS MIPS Technologies NEC, Toshiba
PA-RISC Hewlett Packard Hitachi, Samsung
PowerPC Apple, IBM, Motorola Bul
Sparc Sun Fujitsu, Hyundai
i960 Intel Intel only (Embedded Controller)
Review Exercise
1. A stack is organized such that SP always points at the next empty
location on the stack. This means that Sp can be initialized to 4000 and
the first item in the stack is stored in location 4000. List the
microoperations for the push and pop operations.
2. Convert the following arithmetic expressions from reverse Polish
notation to infix notation.
A B C D E*/— +