MIPS
MIPS
• Basic Components:
- ALU (Arithmetic Logic Unit): Performs mathematical and
logical operations.
- CU (Control Unit): Directs operations within the processor.
- Registers: Small storage units for temporary data.
• Data Flow: Instructions fetched from memory, decoded, and
executed.
• Instruction Set Architecture (ISA): Defines supported operations
and formats.
Instruction Set and Execution
• Types of Instructions:
- Data transfer (MOV, LOAD, STORE)
- Arithmetic & logical (ADD, SUB, AND, OR)
- Control (JUMP, CALL, RETURN)
• Addressing Modes:
- Immediate, Register, Direct, Indirect
• Execution Cycle:
- Fetch → Decode → Execute → Store
Memory and I/O Interface
• Memory Hierarchy:
- Registers → Cache → RAM → Hard Disk
• I/O Interfacing:
- Parallel and Serial communication
- Memory-mapped and I/O-mapped addressing
• Bus Architecture:
- Address Bus (selects memory locations)
- Data Bus (transfers data)
- Control Bus (manages operations)
Advanced Microprocessor Features
PIPELINE SPEEDUP:
If the stages are perfectly balanced, then the time interval between the
instructions in the pipelined processor assuming ideal condition:
Time between instruction pipelined = Time between instruction non
pipelined / No of Pipelined stages
Pipeline Performance Improvement
Hazards occur when the next instruction cannot execute the following clock
cycles.
Types of hazards:
Structural hazard
Data hazard
Control Hazard
a) Structural Hazards
•Occurs when two instructions try to use the same hardware resource
simultaneously.
•Solution: Use separate instruction and data memory or multi-port registers.
b) Data Hazards
•Occurs when an instruction depends on the result of a previous instruction
that has not yet completed.
•In a computer pipeline data hazard arise from the dependency of one
instruction on the previous instruction that is still in the pipeline.
•Example:
The add instruction writes the result in the fifth stage of clock cycle. Sub
instruction must wait – Stall (bubble) for three clock cycles.
Data forwarding:
• As soon as ALU creates sum for the ADD instruction it can be given as
input for SUB instruction.
• If the first instruction is (lw) loaded instead of ADD, then the desired
data is available only after the fourth stage of the first instruction.
• Hence even with the forwarding we must stall for one clock cycle.
a=b+e
c=b+f
Lw $t1, 0($t0)
Lw $t2, 4($t0)
ADD $t3, $t1, $t2
sw $t3, 12($t0)
Lw $t4, 8($t0)
ADD $t5, $t1, $t4
sw $t5, 16($t0)
Reordering of code:
a=b+e
c=b+f
Lw $t1, 0($t0)
Lw $t2, 4($t0)
Lw $t4, 8($t0)
ADD $t3, $t1, $t2
sw $t3, 12($t0)
ADD $t5, $t1, $t4
sw $t5, 16($t0)
Control Hazards
•Occurs due to branch (jump) instructions when the next instruction is
unknown
•It arises from the need to make decision based on the result of the
instruction while the others are executing.
•Example:
•Solution:
• Branch Prediction (guess the branch outcome).
• Branch Delay Slot (reorder instructions to minimize stalls).
1 LOAD
2 ADD LOAD
6 SUB ADD
Pipeline execution:
7 SUB
•Without stalls, one instruction completes per cycle after the pipeline fills.
•Data hazards might require forwarding or stalling to resolve dependencies.
MIPS Pipeline Optimizations
1 LOAD
2 ADD LOAD
6 SUB ADD
7 SUB
delay slot.
•Multiple Issue (Superscalar Execution): Executes multiple
instructions per cycle.
Branch Prediction:
7
IF
LOAD
ADD
SUB
ID
LOAD
ADD
SUB
EX
LOAD
ADD
SUB
MEM
LOAD
ADD
SUB
WB
LOAD
ADD
SUB
When the branches are taken the pipeline stalls- when there is misprediction
Dynamic branch prediction:
The dynamic prediction hardware guesses depending on the behaviour of each branch
and may change the prediction for a branch over the life of a program using runtime
information.
Types:
Cycle IF ID EX MEM WB
1 LOAD
2 ADD LOAD
6 SUB ADD
7 SUB
After one-bit wrong prediction, predicted bit is inverted. Implementation of this approach
is that contains branch prediction buffer ( small memory indexed by the lower portion of
the address of the branch instruction).
The memory contains a bit 1 or 0 ( depending on this whether the branch is recently taken
or not)
Ex:
NT T T T T NT
Even if the branch is almost T we can predict incorrectly twice rather than
ones when it is NT. Prediction accuracy is 80%
1 LOAD
2 ADD LOAD
6 SUB ADD
7 SUB
00 – Strongly NT
11 – Strongly T
10 – Weakly T
01 – Weakly NT
Cycle IF ID EX MEM WB
1 LOAD
2 ADD LOAD
6 SUB ADD
7 SUB