ch8 Cpu New
ch8 Cpu New
• Introduction
• Stack Organization
• Instruction Formats
• Addressing Modes
• Program Control
• Transfer Components
Bus
• Control Components
Control Unit Register
File ALU
Control Unit
R1
R2
R3
R4
R5
R6
R7
Load
(7 lines)
SELA { MUX MUX } SELB
3x8
A bus B bus
decoder
SELD
OPR ALU
Output
ALU Control
Encoding of ALU operations OPR
Select Operation Symbol
00000 Transfer A TSFA
00001 Increment A INCA
00010 ADD A + B ADD
00101 Subtract A - B SUB
00110 Decrement A DECA
01000 AND A and B AND
01010 OR A and B OR
01100 XOR A and B XOR
01110 Complement A COMA
10000 Shift right A SHRA
Examples of ALU Microoperations 11000 Shift left A SHLA
Symbolic Designation
Microoperation SELA SELB SELD OPR Control Word
R1 R2 R3 R2 R3 R1 SUB 010 011 001 00101
R4 R4 R5 R4 R5 R4 OR 100 101 100 01010
R6 R6 + 1 R6 - R6 INCA 110 000 110 00001
R7 R1 R1 - R7 TSFA 001 000 111 00000
Output R2 R2 - None TSFA 010 000 000 00000
Output Input Input - None TSFA 000 000 000 00000
R4 shl R4 R4 - R4 SHLA 100 000 100 11000
R5 0 R5 R5 R5 XOR 101 101 101 01100
6 /48
Ch8. Central Processing Unit
Stack Organization
Stack pointer
4
SP C 3
Push, Pop operations 6 bits B 2
A 1
/* Initially, SP = 0, EMPTY = 1, FULL = 0 */ 0
PUSH POP DR
SP SP + 1 DR M[SP]
M[SP] DR SP SP 1
If (SP = 0) then (FULL 1) If (SP = 0) then (EMPTY 1)
EMPTY 0 FULL 0
Ch8. Central Processing Unit 7 /48
Stack Organization
(3 * 4) + (5 * 6) 34*56*+
6
4 5 5 30
3 3 12 12 12 12 42
3 4 * 5 6 * +
– 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
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)
• The number of address fields in the instruction format
depends on the internal organization of CPU
• Two-Address Instructions
Program to evaluate X = (A + B) * (C + D) :
Addressing Modes
• Addressing Modes
• 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
XR = 100
399 450
AC 400 700
Interrupt Procedure
Interrupt Procedure and Subroutine Call
- The interrupt is usually initiated by an internal or
an external signal rather than from the execution of
an instruction (except for the software interrupt)
Hardware
-program
Compiler
High-Level Instruction
Language Hardware
Set
Architecture
Hardware
Implementation
This may seem nonsensical, since it takes at least once clock cycle
each to fetch, decode and execute an instruction.
Machine- Memory
Dynamic Instruction Reference
Occurrence Weighted Weighted
Pascal C Pascal C Pascal C
ASSIGN 45 38 13 13 14 15
LOOP 5 3 42 32 33 26
CALL 15 12 31 33 44 45
IF 29 43 11 21 7 13
GOTO 3
Other 6 1 3 1 2 1
Call-Return Behavior
And, since function calls and returns are so common, this results in a
significant savings relative to a stack-based approach