0
0
Verilogprogramming~20 mins

When to use non-blocking (sequential) in Verilog - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Non-blocking Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of non-blocking assignments in sequential logic

What is the output of the following Verilog code snippet after one clock cycle?

reg [3:0] a, b;
always @(posedge clk) begin
  a <= b;
  b <= a + 1;
end
Verilog
reg [3:0] a = 0, b = 0;
always @(posedge clk) begin
  a <= b;
  b <= a + 1;
end
// After one positive clock edge, what are the values of a and b?
Aa = 1, b = 1
Ba = 0, b = 1
Ca = 0, b = 0
Da = 1, b = 0
Attempts:
2 left
💡 Hint

Remember that non-blocking assignments update all variables simultaneously after the always block finishes.

🧠 Conceptual
intermediate
1:30remaining
Why use non-blocking assignments in sequential always blocks?

Which reason best explains why non-blocking assignments (<=) are preferred in sequential always blocks triggered by clock edges?

AThey automatically infer combinational logic without needing sensitivity lists.
BThey execute assignments immediately, making simulation faster.
CThey are simpler to write and require less code than blocking assignments.
DThey allow all right-hand side expressions to be evaluated before any left-hand side variables are updated, preventing race conditions.
Attempts:
2 left
💡 Hint

Think about how multiple assignments inside a clocked block should behave simultaneously.

🔧 Debug
advanced
2:00remaining
Identify the problem with blocking assignments in sequential logic

Consider this Verilog code inside a clocked always block:

always @(posedge clk) begin
  a = b;
  b = a + 1;
end

What problem will this cause?

AIt causes a race condition because 'a' is updated immediately, affecting the next assignment to 'b'.
BIt will synthesize correctly with no issues.
CIt causes a syntax error because blocking assignments are not allowed in always blocks.
DIt will cause 'b' to never update.
Attempts:
2 left
💡 Hint

Think about how blocking assignments execute in order inside an always block.

📝 Syntax
advanced
1:30remaining
Which code correctly uses non-blocking assignments in sequential logic?

Which of the following always blocks correctly uses non-blocking assignments for sequential logic?

A
always @(posedge clk) begin
  x &lt;= y;
  y &lt;= x + 1;
end
B
always @(posedge clk) begin
  x = y;
  y = x + 1;
end
C
always @(*) begin
  x &lt;= y;
  y &lt;= x + 1;
end
D
always @(*) begin
  x = y;
  y = x + 1;
end
Attempts:
2 left
💡 Hint

Non-blocking assignments are used in clocked always blocks, not combinational ones.

🚀 Application
expert
2:30remaining
Predict the final values after multiple clock cycles with non-blocking assignments

Given the following Verilog code, what are the values of a and b after 3 positive clock edges?

reg [3:0] a = 0, b = 0;
always @(posedge clk) begin
  a <= b;
  b <= a + 1;
end
AAfter 3 cycles: a = 3, b = 4
BAfter 3 cycles: a = 3, b = 3
CAfter 3 cycles: a = 2, b = 3
DAfter 3 cycles: a = 1, b = 2
Attempts:
2 left
💡 Hint

Trace the values step-by-step, remembering non-blocking assignments update simultaneously after each clock.