Module 3
Module 3
• It defines the supported data types, the registers, how the hardware manages main
memory, key features (such as virtual memory), which instructions a
microprocessor can execute, and the input/output model of multiple ISA
implementations
Instruction formats
• Each instruction is represented by sequence of bits
• The instruction is divided into two fields
• Opcode field
• Operand field
• This operand field further divided into one to four fields.
• This layout of the instruction is known as the “Instruction Format”
• Simple instruction format
Instruction Set category
• Instruction Set is categorized into types based on
• Operation performed
• Number of operand addresses
• Addressing modes.
Instruction Set category
• Based on Operation being performed
• Data movement 🡪 Move data from a memory location or register to
another memory location or register without changing its form.
• Memory - LOAD, STORE, MOV
• I\O Instructions - IN, OUT
• Data processing🡪 Arithmetic and logic (ALU) instructions - Changes the form
of one or more operands to produce a result stored in another location
• Arithmetic - Add, Sub, MUL
• logic Instructions - AND, OR,
Instruction Set category
• Based on Operation being performed
• Flow Control🡪 Any instruction that alters the normal flow of control
from executing the next instruction in sequence
• Conditional
• JNZ, JZ
• Un Conditional
• Jump
Instruction Set category
• Based on Number of operand addresses
• Instruction Set categorized into four categories based on number of operand
address in the instruction.
• 4-Address Instruction
• 3-Address Instruction
• 2-Address Instruction
• 1-Address Instruction
• 0-Address Instruction
Instruction Set category
Three Address Instruction
Example:
is fetched. = 3
• Then the two words representing the operands themselves need to be fetched into he CPU and after the addition
has been performed, Result overwrites Operand =3
• Total= 06
• add Op1Addr Op2Addr
Memory Required to store an Instruction: 2 x 3 bytes = 06
Bytes
1-address
Instruction : accumulator, supplies 1 operand and stores result
• Special CPU register, the
• One memory address used for other operand
• Need instructions to load and store operands:
• LDA OpAddr[M-R]
• STA OpAddr
• This Instruction will require 1X3+1= 4 bytes to encode a 1-address ALU instruction
• Total=03
Fetch Instruction – 2 cycles
Fetch Operand – 1 cycle
(Uses stack to store when PUSH & hence no store in
memory
36 28 12 11 23
Memor Memory M/As M/As Memor
One-address y to to to to y
Store encode Fetch Execut Traffic
load b Acc🡪 b e
add c Acc🡪 Acc+ 2*3=6 1+(1*3)=4 2 1 2+1=3
mpy d c 2*3=6 1+(1*3)=4 2 1 2+1=3
sub e Acc🡪 Acc* 2*3=6 1+(1*3)=4 2 1 2+1=3
store a d 2*3=6 1+(1*3)=4 2 1 2+1=3
Acc🡪 Acc-e 2*3=6 1+(1*3)=4 2 1 2+1=3
Zero-address a🡪 Acc 30 20 10 5 15
Memor Memory M/As M/As Memor
push b
y to to to to y
push c Store encode Fetch Execut Traffic
add e
2*3=6 1+(1*3)=4 2 1 3
push d
2*3=6 1+(1*3)=4 2 1 3
mpy
1*3=3 1 1 0 1
push e 2*3=6 1+(1*3)=4 2 1 3
sub 1*3=3 1 1 0 1
pop a 1+(1*3)=4
2*3=6 2 1 3
Problems – Example 2
Assume 24 bit memory address and one byte opcode.
Practice problems
• Evaluate the expression a = b - c * d and compute memory traffic for 4, 3, 2, 1,and 0 address
machine. Assuming that addresses are 16 bits, data values are 16 bits, opcodes are 8 bits and 1 byte
word length.
• Develop a comparative table for the performance parameters such as memory to store, memory to
encode, M/As to fetch , M/As to execute and total memory Traffic for 4-,3-,2-,1-,0- address
machine instructions. Consider the following specifications: Memory word size is 1 byte,
Memory/register Address size is 2byte, Opcode size is 1 byte.
ii. Compute various performance factors such as memory to store a program, memory to encode a
whole program, Memory access to fetch & execute and memory traffic.
Addressing Modes
• Effective Address
• The address in which the actual operand is available is called as Effective address
Addressing Modes
• Terminologies
• Displacement: It is an 8 bit or 16 bit immediate value given
in the instruction.
• Base: Contents of base register, BX or BP.
• Index: Content of index register SI or DI.
Classification of Addressing Modes
1. Stack (Implied/Implicit) Addressing mode
2. Immediate Addressing mode 9. Auto Increment Addressing Mode
3. (Memory) Direct Addressing mode 10. Auto Decrement Addressing Mode
4. Register Direct Addressing mode
5. (Memory) Indirect Addressing mode
6. Register Indirect Addressing mode
7. Displacement Addressing modes
1. Indexed Addressing mode
2. Base register Addressing mode
3. Relative Addressing Mode
[Link] (Implied/Implicit) Addressing
mode
• Definition of the instruction itself specify the operands implicitly.
• Operand is implied / specified implicitly in the instruction itself.
• Operations like PUSH and POP for the computation
• Zero address instructions in a stack organized computer are implied mode instructions.
• Effective Address (EA) = AC or Stack[SP]
Opcode
• Advantage:
• Instruction specifies a fixed and unvarying address DEC (Decrement A register)
• No memory references CLC (used to reset Carry flag to 0)
PUSH
• Disadvantage:
POP
• Limited Computational Capacity
[Link] Addressing mode
• The simplest form of addressing
• Effective Address (EA) = Value
• Data is a part of instruction itself.
• Example:
Opcode Operand
• MOVE #100, R1
• Here the data 100 is moved to R1.
• MVI #01, A
• MVI stands for Move Immediate. This basically implies move 01 to A.
• Advantage:
• This mode can be used to define and use constants or set of initial values of variables.
• No memory references
• Disadvantage:
• Limited Operand size
3. (Memory) Direct Addressing mode
• The address where data is available is part Advantage:
of the instruction
• Large operand Magnitude, Simple
• The address field contains the effective
address of the operand Disadvantage:
• Limited Address Size
• Effective Address (EA) = LOC
• The change in the location of the
• Example:
program is associated with the change in
• MOVE A, R1 all absolute memory references.
• Here the data in
memory location A
is moved to R1.
4. Register Direct Addressing mode
• Register addressing is similar to Advantage:
direct addressing • No memory Reference
• The only difference is that the address field Disadvantage:
refers to a register rather than a main memory
address • Limited number of registers
• Effective Address (EA) = Ri
• Example:
• MOVE R2, R1
• Here the data in Register R2 is
moved to R1.
5. (Memory) Indirect Addressing mode
• The address field contains the address of Advantage:
effective address of the operand
• Contains a full –length address of the • Large address space
operand Disadvantage:
• Effective Address (EA) = (LOC) or [LOC] • The change in the location of the
• Example: program is associated with the change in
• MOVE (A), R1 all absolute memory references
• Here A – has another memory address
(not data)
• The data in the
address in A
is moved to R1.
6. Register Indirect Addressing mode
• Register indirect is just analogous to Advantage:
indirect addressing in both cases • Large address space
• The only difference is whether the address Disadvantage:
field refers to memory location or a register.
• Extra memory space
• Effective Address (EA) = (Ri) or [Ri]
• Example:
• MOVE (R2), R1
• Here R2 – has memory
address (not data)
• The data in the
address in R2 is
moved to R1.
7. Displacement Addressing modes -
Indexed Addressing mode
• The address field reference a main memory Index
The base register holds the beginning
location of a memory array, while the
address, and the referenced register contain a Register
index register holds the relative position
positive displacement from that address . of an element in the array.
Advantage:
• Effective Address (EA) = (Ri) + X Index value of an
Special Locality
array
Stored
• Example: •
in
Index
• MOVE 20 (R2), R1
Register
• Here R2 – has memory
address (not data).
• The address in R2 is added with the index value
20 which is the EA.
• The data in the
address in R2+20
is moved to R1.
Register - AC ← R1 400
• Two Phases:
– Fetch
– Execute
Phases of Instruction Cycle
• 4 phases of Instruction
Cycle
Phases of Instruction Cycle
• Fetch Phase:
• PC – holds the address of Instruction
• Processor – Fetches the instruction from
memory and stores in IR
• Increment PC
• Unless told Otherwise
• Processor interprets instruction and performs
required actions
• Execute Phase:
• Carry out the actions specified by the
instruction in the IR (execution phase).
• The instruction decoder and control logic unit
is
responsible for implementing the action
specified by the instruction loaded in the IR
Phases of Instruction Cycle
• An instruction can be executed by performing
or more of the following operations in
one
specified
some sequence.
• Transfer a word of datafrom
one processor
register to another or to the ALU.
• Perform an arithmetic or a logic
operation and
store the result in a processor register.
• Fetch the contents of a given memory
location
and load them into a processor register.
• Store a word of data from a processor
Instruction Cycle - State Diagram
• Instruction address calculation (IAC):
• Determine the address of the next
instruction
to be executed. Adding a fixed number
to a next number.
• Instruction fetch: (IF)
• Read the instruction from its memory
location
into the processor.
• Instruction operation decoding (IOD)
• Analyze instruction to determine type
• Operand
of operation to be performed
Address Calculation: (OAC) and
• operand(s) to be involves
If the operation used. the reference to • Data Operation (DO):
an operand in memory or available via • Perform the indicated in the
I/O, then determine the address of the operation
operand. instruction.
• Operand Fetch (OF): • Operand store (OS):
• Fetch the operand from memory or • Write the result into memory or out to
read it from I/O. I/O.
Interrupts
Instruction cycle with Interrupts
Instruction cycle with Interrupts – State
Diagram
Instruction Execution Cycle
ALU
• Arithmetic-Logic Unit (ALU) is the part of a CPU that carries out
arithmetic and logic operations on the operands.
• ALU is divided into two units:
• Arithmetic Unit (AU)
• Logic Unit (LU).
• Some processors contain more than one AU
• For example, one for fixed-point operations and another for floating-
point operations.
• Control Unit (CU) - supplies the data required by the ALU from memory,
or from input devices, and directs the ALU to perform a specific
operation based on the instruction fetched from the memory
ALU
Operations on ALU
• logical operations − These include operations like AND, OR, NOT,
XOR, NOR, NAND, etc.
Flag
s
Module 3 – Data Path and Control Unit
-Hardwired Control
- Microprogrammed Control
Datapath and Control
• CPU can be divided into Data section & Control Section
Control Section
issues control
signals to the
datapath
Recap : Data Path and Control
Data Path and Control
• To execute an instruction, a processor must perform the
following 3 steps:
Data Path and Control – Single Bus
Register
Transfer
ALU Operation
Instruction
Execute
Data Path and Control
– Multiple Bus
Data Path and Control
– Multiple Bus PCo
ut
R=
B
IRi
n
Instruction
Execute MARi
n
QUIZ
Revisit - Stages of Data Path
Stages of Data Path - Examples
• Throughput of a CPU/Bandwidth
• The total amount of work done in a given time.
• another measure of performance -number of tasks (Quantity) completed
per unit time.
Performance Metrics
• MIPS
• Millions of instructions per second
• MFLOPS
• Millions of floating point operations(FLO) per
second
Performance Metrics
• To maximize performance, we want to minimize response time or
execution time for task. Thus, we can relate performance and execution
time for a computer X:
PerformanceA = n × PerformanceB
Performance Metrics - Example
PerformanceX = n × PerformanceY
Performance Metrics
• For some program running on
machine X, 1
Performance
Execution
=
time(X)
• "X is n times faster than Y" –
represented as Performance(X)
=
Performance(Y)
n
• Problem: Machine A runs a program in 20 seconds. Machine B
runs the same program in 25 seconds. How many times faster
is machine A?
Computer Clock
• Almost all computers are constructed using a clock that determines
when events take place in the hardware.
• These discrete time intervals are called clock cycles (ticks, clock
ticks, clock periods, clocks, cycles).
clock period
1
𝐶𝑙𝑜𝑐𝑘 𝑅𝑎𝑡𝑒 =
𝑐𝑙𝑜𝑐𝑘 𝑐𝑦𝑐𝑙𝑒 𝑇𝑖𝑚𝑒
45,000,000 * (1 / 1,000,000) = 45
seconds
Practice Problems
• Example 2:
• CPU clock rate is 500 MHz
• Program takes 45 million cycles to execute
• What’s the CPU time?
= 24/20 = 1.2
times
Machine A is
faster
Practice Problems
• Example 4:
Our favorite program runs in 10 seconds on computer A, which
has a 2 GHz clock. We are trying to help a computer designer
build a computer, B, which will run this program in 6
seconds. The designer has determined that a substantial
increase in the clock rate is possible, but this increase will affect
the rest of the CPU design, causing computer B to require 1.2
times as many clock cycles as computer A for this
program. What clock rate should we tell the designer to target?
Practice Problems
A – Exec time = 10 sec, Clock rate –
• Example 4: 2GHz B- [Link] = 6 sec.
Clock cycle of B = 1.2 (clock cycle of
Solution A)
Find Clock rate of B?
Practice Problems
A – Exec time = 10 sec, Clock rate –
• Example 4: 2GHz B- [Link] = 6 sec.
Clock cycle of B = 1.2 (clock cycle of
Solution A)
Find Clock rate of B?
Practice Problems
• Example 5:
Suppose we have two implementations of the same instruction
set architecture. Computer A has a clock cycle time of 250 ps
and a CPI of
2.0 for some program, and computer B has a clock cycle time of
500 ps and a CPI of 1.2 for the same program. Which computer
is faster for this program and by how much?
Practice Problems
• Example 5:
Solution
Average Cycles per Instruction
𝑛
∑𝑖=1 𝐼C𝑖 ∗𝐶𝑃𝐼𝑖
• Total CPI=
Instruction count(Ic)
Practice Problems
• Example
6:
Practice Problems
• Example 6:
Solution
B is faster
Since Clock cycle time is not given, we can estimate using CPU clock
cycles itself
Practice Problems
• Example 6:
Solution
Practice Problems
• Example
7:
Practice Problems
• Example 7:
Solution
With Frequency
• Ic 🡪 Instruction count 𝐼𝑐 ∗𝑓
• T🡪 CPU time CPU clock cycles ∗106
• f🡪 Clock rate
• CPI🡪 Cycles Per
Instruction
Practice Problems
• Example
10:
Practice Problems
• Example
11:
Practice Problems
• Example 12:
Assume that a benchmark has 100 instructions with the clock
rate of 300Mhz. 20% instructions are loads/stores (each take 3
cycles), 40% instructions are adds (each takes 2 cycles), and
40% instructions are square root (each takes 60 cycles), what
is the CPI and MIPS rate for this benchmark?