0% found this document useful (0 votes)
39 views74 pages

Coam2 - ST

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views74 pages

Coam2 - ST

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 74

By Dr Pawan Singh Mehra

Computer Organisation and


Architecture
Course Code: CO206
Module-2: Control Unit

1
Contents of Module 2
 Instruction types, Formats, Instruction cycles and sub cycles.
By Dr Pawan Singh Mehra

 Micro-operations, execution of a complete instruction.


 Hardwired and micro programmed control.
 Microprogrammed sequencing.
 Wide branch addressing.
 Micro- instructions with next address field.
 Pre-fetching micro instructions.
 Concept of horizontal and vertical micro-programming.
2
Introduction
 Every different processor type has its own design (different registers, buses, micro-
operations, machine instructions, etc)
By Dr Pawan Singh Mehra

 Modern processor is a very complex device. It contains


Many registers
Multiple arithmetic units, for both integer and floating point calculations
The ability to pipeline several consecutive instructions to speed execution
 However, to understand how processors work, we will start with a simplified
processor model
 This is similar to what real processors were like ~25 years ago
 M. Morris Mano introduced a simple processor model he calls the Basic Computer
 The memory has 4096 =212 words in it (i.e. 12 bits to select a word in memory)
 Each word is 16 bits long.
 We will use this to introduce processor organization and the relationship of the RTL
model to the higher level computer processor
3
Instruction
 Program
By Dr Pawan Singh Mehra

 A sequence of (machine) instructions


 (Machine) Instruction
 A group of bits that tell the computer to perform a specific
operation (a sequence of micro-operation)
 The instructions of a program, along with any needed data are
stored in memory
 The CPU reads the next instruction from the memory
 It is placed in an Instruction Register (IR)
 Control circuitry in control unit then translates the instruction into
the sequence of micro-operations necessary to implement it.
4
Instruction Types
 A computer has a set of instructions which can be classified as
By Dr Pawan Singh Mehra

 Data transfer Instructions


 Arithmetic Instructions
 Logical Instructions
 Shift and Rotate Instructions
 Program control Instructions
 Input/Output Instructions

5
Data Transfer Instruction
By Dr Pawan Singh Mehra

Instruction Mnemonic Description


Load LDA It transfers data from specified location to
the processor register usually accumulator
Store STA It transfers data from the processor
register(usually accumulator) to the specified
memory location
Move MOV It transfers data between processor register
and memory or between two memory words
Exchange XCH It swaps data between two registers or a
register and a memory word

6
Arithmetic Instruction
By Dr Pawan Singh Mehra

Instruction Mnemonic Description


Add ADD It adds the content of two operands
Subtract SUB It subtracts the contents of two operands
Increment INC It adds 1 to the value stored in the register or
a memory word
Decrement DEC It subtracts 1 from the value stored in the
register or a memory word
Multiply MUL It multiplies the content of two operands
Divide DIV It divides the content of two operands
Negate NEG It gives the 2’s Complement of the specified
operand 7
Logical Instruction
By Dr Pawan Singh Mehra

Instruction Mnemonic Description


AND AND It logically ANDs the individual bits of the
operands
OR OR It logically ORs the individual bits of the
operands
Exclusive OR XOR It logically Ex-ORs the individual bits of the
operands
Clear CLR It causes the specified operand to be
replaced by 0s
Complement COM It gives the 1’s complement of the specified
operand
8
Shift and Rotate Instruction

Instruction Mnemonic Description


By Dr Pawan Singh Mehra

Logical Shift Right SHR It shifts the contents of the specified register 1-bit
position towards right and fills the vacant bit with
zero
Logical Shift Left SHL It shifts the contents of the specified register 1-bit
position towards left and fills the vacant bit with zero
Arithmetic Shift Right ASHR It shifts the contents of the specified register 1-bit
position towards right and fills the vacant bit with
previous sign bit
Arithmetic Shift Left ASHL It shifts the contents of the specified register 1-bit
position towards left and fills the vacant bit with zero
Rotate Left ROL It rotates (circular shifts) left the contents of the
specified register
Rotate Right ROR It rotates (circular shifts) right the contents of the
specified register
9
Program Control Instruction
By Dr Pawan Singh Mehra

Instruction Mnemonic Description


Branch BR It transfers program control to the specified
address
Jump JMP It transfers program control to the specified
address
Compare CMP It compares the content of two registers
Test TST It performs bitwise AND operation on two
operands
Skip SKP It skips the next instruction

10
Input/Output Instruction
By Dr Pawan Singh Mehra

Instruction Mnemonic Description


Input INP Load a character in Accumulator register
from input port
Output OUT Send a character to output port from
Accumulator register
Skipping SKI It skips the next instruction if input flag=1
instruction
from input
Skipping SKO It skips the next instruction if output flag=1
instruction
from output

11
Instruction Format
 A Computer instruction is often divided into two parts
 An opcode (Operation Code) that specifies the operation for that instruction
By Dr Pawan Singh Mehra

 An address that specifies the registers and/or locations in memory to use for that
operation
 In the Basic Computer, since the memory contains 4096 (= 212) words, we need 12 bit
to specify which memory address the instruction will use
 In the Basic Computer, bit 15 of the instruction specifies the addressing mode (0:
direct addressing, 1: indirect addressing)
 Since the memory words, and hence the instructions, are 16 bits long, that leaves 3 bits
for the instruction’s opcode

Instruction Format
15 14 12 11 0
I Opcode Address

Addressing
mode
12
Addressing Modes
The address field of an instruction can represent either
 Direct address: it has the address of the operand (direct access to operand)
By Dr Pawan Singh Mehra

 Indirect address: It is the address in memory from which the address of the operand can be fetched.
Direct addressing Indirect addressing

22 0 ADD 457 35 1 ADD 300

300 1350

457 Operand
1350 Operand

+ +
AC AC

Effective Address (EA)


 The address, that can be directly used without modification to access an operand for a computation-
type instruction, or as the target address for a branch-type instruction 13
Basic Computer Registers
Registers in the Basic Computer
By Dr Pawan Singh Mehra

14
By Dr Pawan Singh Mehra

Common Bus System

15
By Dr Pawan Singh Mehra

Common Bus System

16
Common Bus System
 Three control lines, S2, S1, and S0 control which register the bus selects as its input
By Dr Pawan Singh Mehra

 Either one of the registers will have its load signal activated, or the memory will have its read signal
activated
 Will determine where the data from the bus gets loaded
 The 12-bit registers, AR and PC, have 0’s loaded onto the bus in the high order 4 bit positions
 When the 8-bit register OUTR is loaded from the bus, the data comes from the low order 8 bits on
the bus
17
Basic Computer Instruction Format
By Dr Pawan Singh Mehra

18
Basic Computer Instructions
By Dr Pawan Singh Mehra

19
Control Unit of Basic Computer
By Dr Pawan Singh Mehra

20
By Dr Pawan Singh Mehra

Timing Signal

21
Instruction Cycle
 In Basic Computer, a machine instruction is executed in the following
cycle:
By Dr Pawan Singh Mehra

1. Fetch an instruction from memory


2. Decode the instruction
3. Read the effective address from memory if the instruction has an
indirect address
4. Execute the instruction

 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
22
Elements of Instruction
 Operation Code(OPCODE)
By Dr Pawan Singh Mehra

 Specifies the operation to be performed


 The operation is specified by a binary code, known as the operation code,
opcode do ADD, SUB,DIV,LOAD,.
 Source Operand reference
 The operation may involve one or more source operands, that is, operands
that are inputs for the operation
 Result Operand reference
 The operation may produce a result
 Next Instruction reference
 This tells the processor where to fetch the next instruction after the
execution of this instruction is complete

23
Instruction Cycle
By Dr Pawan Singh Mehra

Fetch

Decode

Execute

24
Fetch Cycle
 The address of next instruction is fetched from the program counter
and stored in address register.
By Dr Pawan Singh Mehra

 AR PC
 IR M[AR], PC PC+1

 The instruction read from memory is then placed in the instruction


register.
 Program counter is incremented by 1.

25
Decode Cycle
 In decode operation processor decode the instruction which
is fetched from memory
By Dr Pawan Singh Mehra

I IR(15), Decode IR(12-14) , AR IR(0-11)

 0-11 bits in the instruction format are store in the address


register.
 12-14 bits are decoded.

 15 bit is I means direct or indirect address.

26
Execute Cycle
 After decoding the instruction, the third timing signal is active.
By Dr Pawan Singh Mehra

 There are three types of instruction:-


 Memory Reference
 Register Reference
 I/O Reference

 If D=1 and IR(15)=0, that means the instruction is register reference.

 If D=1 and IR(15)=1, that means the instruction is I/O reference.

27
Execute Cycle
 If D=0 and IR(15)=0, that means memory reference instruction is direct
By Dr Pawan Singh Mehra

address instruction.

 If D=0 and IR(15)=1, that means memory reference instruction is indirect


address instruction

 AR M[AR], AR holds the address part of the instruction

 After the instruction is executed, SC is cleared to 0 and control returns to


the fetch phase.

28
Register Reference Instructions
Register Reference Instructions are identified when
- D7 = 1, I = 0
By Dr Pawan Singh Mehra

- Register Ref. Instr. is specified in b0 ~ b11 of IR


- Execution starts with timing signal T3

r = D7 IT3 => Register Reference Instruction


Bi = IR(i) , i=0,1,2,...,11
r: SC  0 CLA: Clear Accumulator
CLA rB11: AC  0 CLE: Clear E
CLE rB10: E0
CMA: Complement AC
CMA rB9: AC  AC’
CME rB8: E  E’ CME: Complement E
CIR rB7: AC  shr AC, AC(15)  E, E  AC(0) CIR: Circulate right
CIL rB6: AC  shl AC, AC(0)  E, E  AC(15) CIL: Circulate Left
INC rB5: AC  AC + 1 INC: Increment AC
SPA rB4: if (AC(15) = 0) then (PC  PC+1) SPA: Skip if positive
SNA rB3: if (AC(15) = 1) then (PC  PC+1) SNA: Skip if negative
SZA rB2: if (AC = 0) then (PC  PC+1) SZA: Skip if AC zero
SZE rB1: if (E = 0) then (PC  PC+1) SZE: Skip if E zero
HLT rB0: S  0 (S is a start-stop flip-flop)
HLT: Halt Computer
29
Memory Reference Instructions
- The effective address of the instruction is in AR and is placed there during timing signal T2 when I = 0,
By Dr Pawan Singh Mehra

or during timing signal T3 when I = 1


- Memory cycle is assumed to be short enough to complete in a CPU cycle
- The execution of MR instruction starts with T4

Operation
Symbol Symbolic Description
Decoder
AND D0 AC  AC  M[AR]
ADD D1 AC  AC + M[AR], E  Cout
LDA D2 AC  M[AR]
STA D3 M[AR]  AC
BUN D4 PC  AR
BSA D5 M[AR]  PC, PC  AR + 1
ISZ D6 M[AR]  M[AR] + 1, if M[AR] + 1 = 0 then PC  PC+1

BUN: Branch Unconditionally


BSA: Branch and save return address
ISZ: Increment and Skip if Zero

30
Input Output Instructions
D7IT3 = p => Input Output Instruction
By Dr Pawan Singh Mehra

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

31
Instruction Types(on the basis of addresses)
Stack type organization
By Dr Pawan Singh Mehra

0-Address instruction
Accumulator type organization
 1-Address Instructions
General Register Organization
2-Address instructions
3-Address instructions

32
Zero Address Instruction
 All addresses implicit, e.g. ADD
By Dr Pawan Singh Mehra

 Uses a stack, e.g. POP A, POP B


X= (A+B)*(C+D)
PUSH A
PUSH B
ADD
PUSH C
PUSH D
ADD
MUL
POP X

33
1- Address Instruction
One address instruction use an implied accumulator (AC) register for all data manipulation
now we see the same example
By Dr Pawan Singh Mehra

X= (A+B)*(C+D)
LOAD A
ADD B
STORE T
LOAD C
ADD D
MUL T
STORE X
All operation are done between the AC register and a memory operand
T is the address of a temporary memory location for storing intermediate result

34
2- Address Instructions
One address is used as operand and result both.
Most common in commercial in computers . Each address field can specify either a
By Dr Pawan Singh Mehra

processes register on a memory word

X= (A+B)*(C+D)
MOV R1, A
ADD R1, B
MOV R2, C
ADD R2, D
MUL R1,R2
MOV X, R1
Reduces length of instruction
Requires some extra work , temporary storage
MOV instruction moves or transfers the operand to and from memory and processor
registers.
First symbol listed in an instruction is assumed to be both a source and destination . 35
3-Address Instructions
Computer with three address instructions formats can use each address field to specify
either a processor register or a memory operand .
By Dr Pawan Singh Mehra

X= (A+B)*(C+D)
ADD R1,A,B
ADD R2,C,D
MUL X,R1,R2

Needs very long words to hold everything


It is assumed that the computer has two processor registers R1 andR2
The advantage of three address format is that it results in short programs when
evaluating arithmetic expression .
The disadvantage is the binary coded instructions require too many bits to specify

36
Instances for instructions
By Dr Pawan Singh Mehra

37
Execution of Complete Instruction
ADD (R3) R1
 Fetch the instruction from memory-IR
By Dr Pawan Singh Mehra

 Fetch the operand from memory


 Perform Addition operation
 Load the result into R1

STEP ACTION
1 PCout, MARin, Read, Select Constant 1, Add, Zin
2 Zout, PCin, Yin ,WMFC
3 MDRout, IRin
4 R3out, MARin, Read
5 R1out, Yin, WMFC
6 MDRout, select Y, Add, Zin
7 Zout, R1in, END

38
Unconditional Branch
By Dr Pawan Singh Mehra

STEP ACTION
1 PCout, MARin, Read, Select Constant 1, Add, Zin
2 Zout, PCin, Yin ,WMFC
3 MDRout, IRin
4 Offset-field-of-IRout, Add, Zin
5 Zout, PCin, END

39
Multiple Bus Organisation
By Dr Pawan Singh Mehra

40
Generation of Control Signal

 To execute instructions, the processor must have some means of


By Dr Pawan Singh Mehra

generating the control signals needed in the proper sequence.

 Two categories:
 Hardwired Control
 Micro-programmed control

41
By Dr Pawan Singh Mehra

Hardwired Control

42
Hardwired Control

 The control unit uses fixed logic circuits to interpret instructions and
By Dr Pawan Singh Mehra

generate control signals for them


 The fixed logic circuits use contents of the control step counter,
contents of the instruction register, contents of conditional code
flag and the external input signals such as MFC and interrupts
requests to generate control signal.

43
Hardwired Control Signal Example

• Zin = T1 + T6 • ADD + T4 • BR + …
By Dr Pawan Singh Mehra

44
Micro-programmed Control
By Dr Pawan Singh Mehra

45
Micro-programmed Control

 CONTROL MEMORY
By Dr Pawan Singh Mehra

 The micro routines for all the instructions in the instruction set of a
computer are stored in a special memory called the Control
Memory/Store
 CONTROL WORD
 It is a word whose individual bits represent the various control signals.
 MICRO-ROUTINE
 A sequence of control words corresponding to the control sequence of
a machine instruction constitutes the micro-routine for that instruction.
 MICRO-INSTRUCTION
 The individual control words in the micro-routine are referred to as
micro-instruction
46
Micro-programmed Control
By Dr Pawan Singh Mehra

47
Difference between Hardwired and Micro-programmed Control

HARDWIRED CONTROL MICRO-PROGRAMMED


ATTRIBUTE
By Dr Pawan Singh Mehra

UNIT CONTROL UNIT


SPEED FAST SLOW
COST OF
MORE CHEAPER
IMPLEMENTATION
NOT FLEXIBLE, DIFFICULT TO FLEXIBLE, NEW INSTRUCTIONS CAN BE
FLEXIBILITY
MODIFY FOR NEW INSTRUCTION ADDED

ABILITY TO HANDLE COMPLEX


DIFFICULT EASIER
INSTRUCTION

INSTRUCTION SET SIZE SMALL LARGE

CONTROL MEMORY ABSENT PRESENT

48
Micro Instruction
A straightforward way to structure microinstructions is to assign one bit
By Dr Pawan Singh Mehra

position to each control signal.


However, this is very inefficient.
The length can be reduced: most signals are not needed simultaneously,
and many signals are mutually exclusive.
All mutually exclusive signals are placed in the same group in binary
coding.

49
Partial Format for Micro Instruction
By Dr Pawan Singh Mehra

50
Micro Instruction types
The grouping of control signals can be done in one of the two ways
By Dr Pawan Singh Mehra

Vertical Micro-programming
 Each micro-instruction specifies single (or few) micro-operations to be
performed.

Horizontal Micro-programming
Each micro-instruction specifies many different micro-operations to
be performed in parallel.

51
Difference between Horizontal & Vertical Microprogramming

HORIZONTAL MICRO-PROGRAMMING VERTICAL MICRO-PROGRAMMING


By Dr Pawan Singh Mehra

Long formats Short formats

Ability to express a high degree of parallelism Limited ability to express parallel micro-operations

Considerable encoding of the control


Little encoding of the control information
information

Useful when higher operating speed is required Slower operating speed

52
Addressing Modes
Specifies a rule for interpreting or modifying the address field of
the instruction (before the operand is actually referenced)
By Dr Pawan Singh Mehra

Variety of addressing modes


 to give programming flexibility to the user
 to use the bits in the address field of the instruction
efficiently

53
Types of Addressing Modes
Implied Addressing Mode
Immediate Addressing Mode
By Dr Pawan Singh Mehra

Register Addressing Mode


Register Indirect Addressing Mode
Autoincrement/ Autodecrement Addressing Mode
Direct Addressing Mode
Indirect Addressing Mode
Relative Addressing Mode
PC Relative Addressing Mode
Indexed Addressing Mode
Base Register Addressing Mode
54
Implied Addressing Mode
Address of the operands are specified implicitly in the definition
of the instruction
By Dr Pawan Singh Mehra

- No need to specify address in the instruction


- EA = AC, or EA = Stack[SP]
Examples : CLA, CME, INP

55
Immediate Addressing Mode
Instead of specifying the address of the operand, operand itself
is specified
By Dr Pawan Singh Mehra

- 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
Example : ADD 5

opcode operand

56
Register Addressing Mode
Address specified in the instruction is the register address
- Designated operand need to be in a register
By Dr Pawan Singh Mehra

- 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)

57
Register Indirect Addressing Mode
Instruction specifies a register which contains the memory
address of the operand
By Dr Pawan Singh Mehra

- 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)

58
Autoincrement/Autodecrement Addressing Mode
When the address in the register is used to access memory, the
value in the register is incremented or decremented by 1
By Dr Pawan Singh Mehra

automatically
Example:
 Autoincrement: Load R1, (R2)+ is interpreted as R1 ← [[R2]]
followed by R2 ← [R2] + d where d is step size(step size is
dependent on size of operand).
 Autodecrement: Load R1, -(R2) is interpreted as R2 ← [R2] – d
followed by R1 ← [[R2]] where d is step size size(step size is
dependent on size of operand)

59
Direct Addressing Mode
Instruction specifies the memory address which can be used
directly to access the memory
By Dr Pawan Singh Mehra

- Faster than the other memory addressing modes


- Too many bits are needed to specify the address for a large
physical memory space
- EA = IR(addr) (IR(addr): address field of IR)

60
Indirect Addressing Mode
The address field of an instruction specifies the address of a
memory location that contains the address of the operand
By Dr Pawan Singh Mehra

- 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)]

61
Relative Addressing Mode
The address field of an instruction specifies the part of the address
(abbreviated address) which can be used along with a designated
By Dr Pawan Singh Mehra

register to calculate the effective address of the operand


- Address field of the instruction is short
- Large physical memory can be accessed with a small number of
address bits
- EA = f(IR(address), R), R is sometimes implied
3 different Relative Addressing Modes depending on R;
* PC Relative Addressing Mode (R = PC)
- EA = PC + IR(address)
* Indexed Addressing Mode (R = XR, where XR: Index Register)
- EA = XR + IR(address)
* Base Register Addressing Mode
(R = BAR, where BAR: Base Address Register)
- EA = BAR + IR(address) 62
Addressing Modes Example
By Dr Pawan Singh Mehra

63
Micro-Programmed Sequencing
If all micro-programs require only straightforward sequential execution of
microinstructions except for branches, letting a μPC governs the
By Dr Pawan Singh Mehra

sequencing would be efficient.


However, two disadvantages:
 Having a separate micro-routine for each machine instruction results
in a large total number of microinstructions and a large control store.
 Longer execution time because it takes more time to carry out the
required branches.
Example: Add src, Rdst
Four addressing modes: register, autoincrement, autodecrement, and
indexed (with indirect forms).

64
Micro-Program for Add src Rdst
By Dr Pawan Singh Mehra

65
Wide Branch Addressing
Generating branch addresses becomes more difficult as the number of
branches increases.
By Dr Pawan Singh Mehra

Programmable Logic Array can be used to generate the required branch


address.
The simple and inexpensive way of generating branch addresses is known
as wide branch addressing
This is achieved by connecting the opcode bits of the instruction register
as inputs to the PLA which acts as decoder.
The output of the PLA is the address of the desired micro-routine.

66
Micro Instruction with Next Address Field
The micro-program requires several branch microinstructions, which
By Dr Pawan Singh Mehra

perform no useful operation in the datapath.


A powerful alternative approach is to include an address field as a part of
every microinstruction to indicate the location of the next microinstruction
to be fetched.
Pros: separate branch microinstructions are virtually eliminated; few
limitations in assigning addresses to microinstructions.
Cons: additional bits for the address field (around 1/6).
67
Micro Instruction with Next Address Field
By Dr Pawan Singh Mehra

68
Micro Instruction with Next Address Field
By Dr Pawan Singh Mehra

69
Implementation of Micro-routine using next Micro-instruction address field
By Dr Pawan Singh Mehra

70
Prefetching Microinstructions
The disadvantage of micro-programmed control is that it results slower
By Dr Pawan Singh Mehra

operating speed because of the time it takes to fetch micro-instructions


from the control memory.
This problem can be solved by prefetching the next microinstruction while
the current one is being executed.
In this technique, the execution time can be overlapped with the fetch
time.

71
Complex Instruction Set Computer(CISC)
A computer system with large number of instructions.
By Dr Pawan Singh Mehra

Large number of addressing modes.


It uses Variable length instruction format.
It has some instructions that perform specialized task and are used
infrequently.
It has instructions that manipulate operands in memory.
Some examples are IBM 370/168, Intel 80386, Intel 80286, Sun-3/75.

72
Reduced Instruction Set Computer(RISC)
It has relatively few instructions.
By Dr Pawan Singh Mehra

In comparison to CISC, it has few addressing modes.


The memory access is limited to load and store instructions.
All the operations are done within the registers of the CPU.
Single cycle instruction execution.
Fixed length easily decoded instruction format.
Hardwired control unit rather than micro-programmed control unit.
Some examples are MIPS R2000, SUN SPARC, Intel i860, Motorola 8800.
73
Examples of CISC and RISC
By Dr Pawan Singh Mehra

74

You might also like