Course contentsShow
← Computer Science
Lesson 1168 of 2,87227. Pipelining and PerformanceFree lesson

Pipeline Stalls and Bubbles

How inserting NOPs (bubbles) into the pipeline delays dependent instructions to resolve data hazards.

Pipeline Stalls and Bubbles

What You'll Learn

You'll learn how processors insert "bubbles" (NOPs or no-operation instructions) into the pipeline to prevent data hazards from causing incorrect results.

The Problem: Instructions That Can't Proceed

When a data hazard occurs—say, instruction B needs a result that instruction A hasn't finished computing yet—the pipeline has a problem. If B tries to execute too early, it will read wrong data. The solution? Force B to wait.

What is a Pipeline Stall?

A pipeline stall (also called a pipeline bubble) is an intentional delay inserted into the pipeline. The processor stops fetching new instructions and inserts a NOP (no operation) into one or more pipeline stages.

Think of it like a factory assembly line: if Station 3 needs a part that Station 2 hasn't finished yet, Station 3 must idle (do nothing) for one or more cycles until the part is ready.

How Bubbles Work

When the control unit detects a data hazard, it:

  1. Freezes the instruction that needs data (keeps it in the same stage)
  2. Inserts a bubble (NOP) into the next stage
  3. Repeats until the data dependency is resolved

The bubble travels through the pipeline like an empty slot, wasting that cycle but ensuring correctness.

Example Scenario

Cycle 1: ADD R1, R2, R3  (computes R1, finishes in cycle 4)
Cycle 2: SUB R4, R1, R5  (needs R1 — hazard detected!)
         → Insert bubble, stall SUB
Cycle 3: (bubble travels through pipeline)
Cycle 4: SUB can now safely read R1

The bubble costs performance—it's wasted time—but guarantees the SUB instruction reads the correct value from R1.

Key Takeaway: Pipeline bubbles are intentional NOPs inserted to delay dependent instructions, resolving data hazards at the cost of performance by creating idle cycles in the pipeline.