Professional Documents
Culture Documents
UNIT-III
software
instruction set
hardware
ISA: Design Issues
Where are operands stored? (During Operation)
• registers, memory, stack, accumulator
CISC RISC
Complex Instruction Set Computer (CISC)
The small and slow memory, backward instruction set compatibility constraints led to the
development of CISC.
A small number of general purpose registers because instructions can operate directly
on memory.
The early MIPS architectures were 32-bit, with 64-bit versions added later.
•In addition to the opcode, R-type instructions specify three registers, a shift amount field,
and a function field
•op (opcode): basic operation of instruction – also determines format – op = 0 for all R-type
instructions
• funct: function variant (e.g. add has funct=32 and sub has funct=34)
Example R-Type Instruction
add Rd, Rs, Rt ; Rd = Rs + Rt
•rt: destination register for addi or loads, second operand for beq
• Datapath
– A hardware unit that process data and addresses
in the CPU
– It includes
Instruction and Data Memories, Registers, ALUs,
Adders and mux’s, …
Building a Datapath
The subset of the core MIPS instruction set
Arithmetic/logical Instructios
add, sub, and, or
Memory reference Instructions
lw, sw
Branch/Control transfer Instructions
branch equal(beq), jump(j)
“Simplicity favors regularity”
For every instruction in all 3 classes of instructions, the first two steps are
identical:
Send the program counter (PC) to the memory that contains the address and
fetch the instruction from the memory.
Read one or two registers, using fields of the instruction to select the
registers to read.
For the load/store word instruction, we need to read only one register, but most other
instructions require reading two registers.
“Simplicity favors regularity”
After these two steps, every instruction uses ALU:
Memory-reference instructions for an address calculation
Arithmetic-logical instructions for the operation execution
Branches for comparison
•Fetch Instruction.
•Decode and Fetch registers
operands
•To compute a memory
address (for a load or
store)
•To compute an
arithmetic result (for
arithmetic-logical
instruction)
•To compare (for a
branch)
Abstract view of the implementation of MIPS Subset
A
Y
B
Arithmetic/Logic Unit
Multiplexer
Y = F(A, B)
Y=S?1:0
A
I0 M
u Y ALU Y
I1 x
B
S F
Elements of Datapath
Program Counter
The 32-bit register containing the address of
the instruction in the program being
executed. It is updated at the end of every
clock cycle/fetch instruction step.
Instruction Memory
Consist of set of instructions (Program)
Read-only memory read-only at user level
(so a program may not
modify it's own code), and writeable only by
supervisor level(s),
usually an OS function
Elements of Data path
Data Memory
Consists of data corresponding to program being
executed
Data memory is expected to be modified by a
program, so the access to it is freely given to it's
parent process.
Register File
A register file is a collection of registers in which
any register can be read or written by specifying
the number of the register in the file.
State element that consists of a set of registers
(read and write operations valid).
The processor’s 32 general-purpose registers are
stored in a structure called a register file.
Elements of Data path
Sign Extension Unit
The sign extension unit has a m-bit input that is sign-
extended into a n-bit result appearing on the output.
If ten bits are used to represent the value "11 1111 0001" 16-bit input and 32-bit output
(decimal negative 15) using two's complement, and this is
sign extended to 16 bits, the new representation is "1111
1111 1111 0001". Thus, by padding the left side with
ones, the negative sign and the value of the original
number are maintained.
Datapath: Instruction Fetch and Increment
To execute any instruction, the processor must fetch the instruction from instruction
memory.
To prepare for executing the next instruction, the processor must also increment the
program counter so that it points at the next instruction, 4 bytes later.
Increment by 4
for next
32-bit instruction
register
Datapath: R-Format Instructions
• Read two register operands
• Perform ALU operation on the contents of the registers
• Write result to a register.
Read 4
Register 1 Read
data 1
Read A Zero
Instruction
Register 2 L
U Result
Write Read
Register data 2
Write Registers
Data
RegWrite
[$t1] @ [$t2]
32
{ +, -, AND, OR, etc.}
Memory-Reference Instruction (Load/Store)
• Read one register operand
• Calculate address using base register and 16-bit offset from instruction
• Perform operation
– Load: Read memory and load register
– Store: Write register value to memory
• Elements required
– Data Memory Unit
– ALU
– Register File
– Sign-Extension Unit
Datapath: Load/Store
lw $t1, $t2(Offset_value)
op rs rt address ALU control
MemWrite
Read
Register 1 Read
data 1 Zero
Instruc- Read A
tion Register 2 L Read
U Address data
Write Read Result
Register data 2
Write Registers Dmem
Write
Data
Data
RegWrite
Sign MemRead
Extend
16 32
Branch Instructions
• Three operands, two registers that are compared for equality, and a
16-bit offset used to compute the branch target address
• Element required
– Register File
– ALU
– Adder
– Sign-Extension Unit
Datapath: Branch Instructions
Sign-bit wire
replicated
Creating Single Datapath
• Single Datapath : The hardware unit designed to follow the sequence
Fetch-Decode-Execute
• The simplest datapath will attempt to execute all instructions in one clock
cycle.
• Address bus: A system bus which is used to specify a physical address to memory.
When a processor needs to read/write to a memory location, it specifies that memory location
on the address bus. The width of the address bus determines the amount of memory a system
can address. For example, a system with a 32-bit address bus can address 232(4,294,967,296)
memory locations. If each memory location holds one byte, the addressable memory space is 4
GB.
• Data bus: A system bus which is used to transport data from memory to processor and vice-
versa. Different kinds of data buses have evolved along with personal computers and other
pieces of hardware.
• Control bus: A system bus which is used by CPUs for communicating with other devices
within the computer.
• The address bus carries the information about the device with which the CPU is communicating
and the data bus carries the actual data being processed, the control bus carries commands from
the CPU and returns status signals from the devices. For example, if the data is being read or
written to the device the appropriate line (read or write) will be active (logic one).
Execution of Complete Instruction
Cycle
To execute the instructions, the processor must follow the instruction cycle:
Fetch instruction: The processor reads an instruction from memory
(register, cache, main memory).
Decode instruction: The instruction is decoded to determine what
action is required.
Fetch data: The execution of an instruction may require reading data
from memory or an I/O module (If indirect addressing is used).
Execute Operation: The execution of an instruction may require
performing some arithmetic or logical operation on data.
Write data: The results of an execution may require writing data to
memory or an I/O module.
Interrupt: If interrupts are enabled and an interrupt has occurred, save
the current process state and service the interrupt.
Execution of Complete Instruction
Cycle
An instruction may involve one or more operands in memory.
For operands with Indirect addressing, additional memory accesses are
required
Can be thought of as additional instruction sub-cycle
If interrupts are enabled and an interrupt has occurred, save the current
process state and service the interrupt before the next instruction fetch.
Instruction Execution with Indirect Cycle (Software
Interrupt)
Instruction Cycle State Diagram
Data Flow
• Cache Memory
• General Purpose registers
• Pipelining
Pipelining
• A way of speeding up execution of instructions
• Key idea: Overlap execution of multiple instructions
• Pipelining: The new inputs are accepted at one end before previously
accepted inputs appear as outputs at the other end.
Two Stages
Fetch instruction
Execute instruction
• The pipeline has two independent stages. The first stage fetches an
instruction and buffers it. When the second stage is free, the first
stage passes it the buffered instruction. While the second stage is
executing the instruction, the first stage takes advantage of any
unused memory cycles to fetch and buffer the next instruction. This
is called instruction prefetch or fetch overlap.
Two Stage Instruction Pipeline
Two Stage Instruction Pipelining
To achieve improved speed-up, the instruction execution can have more than
two stages,
• Fetch instruction (FI): Fetch the next instruction from memory.
• Decode instruction (DI): Determine the opcode and the operand specifiers.
• Calculate operands (CO): Calculate the effective address of each source
operand.
• Fetch operands (FO): Fetch each operand from memory. Operands in
registers need not be fetched.
• Execute instruction (EI): Perform the indicated operation and store the
result, if any, in the specified destination operand location.
• Write operand (WO): Store the result in memory.
• Pipeline Hazard: When the pipeline, or some portion of the pipeline, must
stall because conditions do not permit continued execution.
• Hazards reduce the performance from the ideal speedup gained by pipelining
• Types of hazards
– Resource
– Data
– Control
Resource/Structural Hazards
• Occurs when two or more instructions in pipeline need same resource (such as
memory, single ALU etc.)
• Executed in serial rather than parallel for part of pipeline
• Fetch instruction stage must idle for one cycle fetching I3.
ADD instruction does not update EAX until end of stage 5, at clock cycle 5 and
SUB instruction needs value at beginning of its stage 2, at clock cycle 4.
Data Hazards
• For correct execution, Pipeline must stall for two clocks cycles
• Without special hardware and specific avoidance algorithms, results in
inefficient pipeline usage
Types of Data Hazards
• True Dependency or Read after write (RAW) or
Flow Dependency
– Occurs when an instruction modifies a register or memory location and
succeeding instruction reads data in that location
– Hazard if read takes place before write complete.
a = b + c;
d = a*e;