VLSI DV Interview Puzzles · All levels

always_comb with NBA and Missing Else

Find the functional bug in this combinational block that sporadically latches stale values.

Puzzle

Difficulty: Medium · Puzzle 3 of 6 · Topic: Debugging Riddles

Find the functional bug in this combinational block that sporadically latches stale values.

Code

systemverilog
always_comb begin
  if (en)
    y <= a & b;
end

Hint

Two independent issues exist.

Step-by-step solution

diagram
1) In combinational logic, missing else means y is not assigned when en=0, inferring latch behavior.
2) Using nonblocking assignment in combinational block adds avoidable delta-cycle behavior and can confuse debug.
3) Correct form assigns y in all paths with blocking assignment.
4) Example fix: always_comb begin if (en) y = a & b; else y = 1'b0; end.

Answer

Answer: Bug is inferred latch plus NBA misuse in combinational logic; assign all paths with blocking assignment.

Why candidates get it wrong

Blaming simulator when issue is pure coding-style semantic mismatch.

Interviewer follow-up

Would `always_latch` be appropriate if latch was actually intended?

Related topics