Blocking vs Non-Blocking: The Bug Hunt
intermediate · sequential · 140 XP
Sign in to write your solution, run it in the simulator and submit it for grading.
Sign in or create a free account →Problem
Blocking vs Non-Blocking: The Bug Hunt
You are given two nearly identical modules. Both are supposed to implement a **3-stage pipeline shift register**: data enters at `a`, passes through `b`, then `c`, shifting one stage per clock.
**Module A (buggy) — uses blocking assignments:**
```verilog
always @(posedge clk) begin
b = a; // blocking
c = b; // blocking — BUT b is already the NEW value!
end
```
**Module B (correct) — uses non-blocking assignments:**
```verilog
always @(posedge clk) begin
b <= a; // non-blocking
c <= b; // non-blocking — b is still the OLD value
end
```
**Your task:** Implement both modules inside a single top-level wrapper. The wrapper outputs `c_buggy` (from Module A) and `c_correct` (from Module B) for comparison.
In Module A: by the time the second line executes, `b` already holds the new value of `a`, so `c` gets `a` directly — the pipeline collapses to zero delay. In Module B: all RHS values are captured before the clock edge, so `c` correctly lags `a` by two cycles.
This is not a style preference — it is the **single most important correctness rule** in RTL design.
Constraints
- Implement module shift_buggy using blocking assignments (=).
- Implement module shift_correct using non-blocking assignments (<=).
- Top module shift_compare instantiates both and exposes c_buggy and c_correct.
- For input sequence a=1,0,0,0,0: c_correct must show the value 2 cycles later than c_buggy.
Examples
Input: a sequence: 1,0,0,0,0 applied cycle by cycle
Output: c_buggy: 1,0,0,0,0 (zero delay) | c_correct: 0,0,1,0,0 (2-cycle delay)
Blocking collapses the pipeline; non-blocking preserves it
Common questions
- What does the Blocking vs Non-Blocking: The Bug Hunt problem ask you to build?
- Blocking vs Non-Blocking: The Bug Hunt You are given two nearly identical modules. Both are supposed to implement a **3-stage pipeline shift register**: data enters at `a`, passes through `b`, then `c`, shifting one stage per clock.
- What constraints does Blocking vs Non-Blocking: The Bug Hunt have?
- Implement module shift_buggy using blocking assignments (=).; Implement module shift_correct using non-blocking assignments (<=).; Top module shift_compare instantiates both and exposes c_buggy and c_correct.; For input sequence a=1,0,0,0,0: c_correct must show the value 2 cycles later than c_buggy.
- What is an example input and output for Blocking vs Non-Blocking: The Bug Hunt?
- Input a sequence: 1,0,0,0,0 applied cycle by cycle gives output c_buggy: 1,0,0,0,0 (zero delay) | c_correct: 0,0,1,0,0 (2-cycle delay). Blocking collapses the pipeline; non-blocking preserves it
- Which Verilog concepts does Blocking vs Non-Blocking: The Bug Hunt practise?
- sequential, blocking, non-blocking, debug, interview.