Chapter 02 Central Processing Unit Case Study
Chapter 02 Central Processing Unit Case Study
- Case Study
Prepared By:
BIJAY MISHRA
(बिजय मिश्र)
[email protected]
@jijibisha
Chapter 2 - Central Processing Unit - Case Study 15 Hrs.
Instruction Format
15 14 12 11 0
I Opcode Address
Addressing
mode
• The number of address fields in the instruction format depends on the internal organization of CPU
CPU Organization (Processor Organization)
• In general, most processors are organized in one of 3 ways
• Single register (Accumulator) organization
• Basic Computer is a good example
• Accumulator is the only general purpose register
• General register organization
• Used by most modern computer processors
• Any of the registers can be used as the source or destination for computer
operations
• 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
Advantages and Disadvantages of CPU Organization Approaches
Stack organization
Advantages: Simple Model of expression evaluation (reverse polish). Short instructions.
Disadvantages: A stack can't be randomly accessed and this makes it hard to generate
efficient code. The stack itself is accessed every operation and becomes a bottleneck.
Accumulator organization
Advantages: Short instructions.
Disadvantages: The accumulator is only temporary storage so memory traffic is the
highest for this approach.
Stack organization:
PUSH X /* TOS M[X] */
ADD
THREE AND TWO-ADDRESS INSTRUCTIONS
• Three-Address Instructions
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) :
Register-Reference Instructions
15 12 11 0
0 1 1 1 Register operation (OP-code = 111, I = 0)
Input-Output Instructions
15 12 11 0
1 1 1 1 I/O operation
(OP-code =111, I = 1)
BASIC COMPUTER INSTRUCTIONS
Memory-Reference Instructions
Register-Reference Instructions
Input-Output Instructions
INSTRUCTION SET COMPLETENESS
A computer should have a set of instructions so that the user can construct machine
language programs to evaluate any function that is known to be computable.
• Instruction Types
Functional Instructions
- Arithmetic, logic, and shift instructions
- ADD, CMA, INC, CIR, CIL, AND, CLA
Transfer Instructions
- Data transfers between the main memory and the processor registers
- LDA, STA
Control Instructions
- Program sequencing and control
- BUN, BSA, ISZ
Input/Output Instructions
- Input and output
- INP, OUT
ADDRESSING MODES
• The addressing mode specifies a rule for interpreting or modifying the address field of
the instruction before the operand is actually referenced.
• The decoding step in the instruction cycle determines the operation to be performed, the
addressing mode of the instruction, and the location of the operands.
300 1350
457 Operand
1350 Operand
+ +
AC AC
• 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
TYPES OF ADDRESSING MODES
• 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)
TYPES OF ADDRESSING MODES
• Autoincrement or Autodecrement Mode
- When the address in the register is used to access memory, the value in the register is
incremented or decremented by 1 automatically
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)
EMPTY 0 FULL 0
Register Stack
MEMORY STACK ORGANIZATION
Memory with Program, Data, and Stack Segments
PUSH: SP SP - 1
M[SP] DR
POP: DR M[SP]
SP SP + 1
- Most computers do not provide hardware to check stack overflow (full stack) or underflow (empty
stack) must be done in software
REGISTERS
• In Basic Computer, there is only one general purpose register, the
Accumulator (AC)
• In modern CPUs, there are many general purpose registers
• It is advantageous to have many registers
• Transfer between registers within the processor are relatively fast
• Going “off the processor” to access memory is much slower
R1
R2
R3
R4
R5
R6
R7
Load
(7 lines)
SELA { MUX MUX } SELB
3x8
A bus B bus
decoder
SELD
OPR ALU
Output
GENERAL REGISTER ORGANIZATION
Control Word
There are 14 binary selection inputs in the unit, and their combined
value specifies a control word.
The 14-bit control word is defined in figure below.
GENERAL REGISTER ORGANIZATION
Examples of Microoperations
• After an instruction is executed, the cycle starts again at step 1, for the
next instruction
Note: Every different processor has its own (different) instruction cycle
Instruction Fetch and Decode Phase
• Sequence of steps required for fetching instruction from memory to CPU
internal register is known as fetch cycle.
• Program execution begins with: PC ← address of first instruction, SC ← 0
• After this, the SC is incremented at each clock cycle until an instruction is
completed, and then it is cleared to begin the next instruction.
• This process repeats until a HLT instruction is executed, or until the power
is shut off.
T0: AR PC
T1: IR M [AR], PC PC + 1
T2: D0, . . . , D7 Decode IR(12-14), AR IR(0-11), I IR(15)
Determine Instruction Type and Execute Phase
D7IT3 = p
IR(i) = Bi, i = 6, …, 11
p: SC 0 Clear SC
INP pB11: AC(0-7) INPR, FGI 0 Input char. to AC
OUT pB10: OUTR AC(0-7), FGO 0 Output char. from AC
SKI pB9: if(FGI = 1) then (PC PC + 1) Skip on input flag
SKO pB8: if(FGO = 1) then (PC PC + 1) Skip on output flag
ION pB7: IEN 1 Interrupt enable on
IOF pB6: IEN 0 Interrupt enable off
MEMORY REFERENCE INSTRUCTIONS
FLOWCHART FOR MEMORY REFERENCE INSTRUCTIONS
Memory-reference instruction
D0 T 4 D1 T 4 D2 T 4 D 3T 4
DR M[AR] DR M[AR] DR M[AR] M[AR] AC
SC 0
D0 T 5 D1 T 5 D2 T 5
AC AC DR AC AC + DR AC DR
SC 0 E Cout SC 0
SC 0
D4 T 4 D5 T 4 D6 T 4
PC AR M[AR] PC DR M[AR]
SC 0 AR AR + 1
D5 T 5 D6 T 5
PC AR DR DR + 1
SC 0
D6 T 6
M[AR] DR
If (DR = 0)
then (PC PC + 1)
SC 0
INTERRUPT CYCLE
- The interrupt cycle is a HW implementation of a branch and save return address operation.
- At the beginning of the next instruction cycle, the instruction that is read from memory is in address 1.
- At memory address 1, the programmer must store a branch instruction that sends the control to an interrupt
service routine
- The instruction that returns the control to the original program is "indirect BUN 0“
- Interrupts can be globally enabled or disabled via the IEN flag (flip-flop).
- If interrupts are enabled, then when either FGI or FGO gets set, the interrupt flip-flop (R) flag also gets set.
(R = FGI V FGO).
The interrupt enable flip-flop IEN can be set and cleared with two instructions (IOF, ION):
IOF: IEN ← 0 (the computer cannot be interrupted)
ION: IEN ← 1 (the computer can be interrupted)
Another flip-flop (called the interrupt flip-flop R) is used in the computer’s interrupt facility to decide when to
go through the interrupt cycle.
FGI and FGO are different here compared so that the computer is either in an Instruction Cycle or in an
Interrupt Cycle.
If R = 0, the CPU goes through a normal instruction cycle.
If R = 1, the CPU branches to the ISR to process an I/O transaction.
FLOWCHART FOR INTERRUPT CYCLE
A
Case Study
on
Power PC Processor
and
Pentium Processor
Assignment For You!
•Assigned Date: 2074/04/15
•Submission Date: 2074/04/22
•Submission Criteria: Assignment would be
accepted only in loose sheets/papers. No
plagiarism, if otherwise found would
immediately be rejected (Both copier and
supplier).
•Note: Assignment submitted after the
deadline would not be entertained.
Book References:
• W. Stalling, “Computer Organization and Architecture”, 7th
edition, Prentice-Hall India Limited, New Delhi.
• A.J. Vande Goor, “Computer Architecture and Design”,
Addison Wesley, Wokingham, UK, 1989
• A.S. Tanenbaum, “Structured Computer Organization”,
Prentice Hall India Limited, new Delhi.
• M. Morris Mano, “Computer System Architecture”, Latest
Edition.
• John P. Hayes, “Computer Architecture and Organization”,
Latest Edition.