Challenge - 5 Problems
Verilog Assignment Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of blocking assignments in sequential statements
What is the output of the following Verilog code snippet after one clock cycle?
reg a, b, c; always @(posedge clk) begin a = 1'b1; b = a; c = b; end
Verilog
reg a, b, c; always @(posedge clk) begin a = 1'b1; b = a; c = b; end
Attempts:
2 left
💡 Hint
Blocking assignments execute in order and update variables immediately.
✗ Incorrect
Blocking assignments (=) update the variable immediately, so b gets the updated value of a, and c gets the updated value of b in the same clock cycle.
❓ Predict Output
intermediate2:00remaining
Output of non-blocking assignments in sequential statements
What is the output of the following Verilog code snippet after one clock cycle?
reg a, b, c; always @(posedge clk) begin a <= 1'b1; b <= a; c <= b; end
Verilog
reg a, b, c; always @(posedge clk) begin a <= 1'b1; b <= a; c <= b; end
Attempts:
2 left
💡 Hint
Non-blocking assignments update variables only after the always block finishes.
✗ Incorrect
Non-blocking assignments (<=) schedule updates to happen after the block ends, so b gets the old value of a, and c gets the old value of b.
🔧 Debug
advanced2:00remaining
Identify the error in mixed blocking and non-blocking assignments
Consider this Verilog code inside an always block triggered by posedge clk:
What problem does this code cause?
reg x, y; always @(posedge clk) begin x = y; y <= x; end
What problem does this code cause?
Verilog
reg x, y; always @(posedge clk) begin x = y; y <= x; end
Attempts:
2 left
💡 Hint
Mixing blocking and non-blocking assignments in the same block can cause timing issues.
✗ Incorrect
Using blocking and non-blocking assignments together in the same always block can cause race conditions because blocking assignments update immediately while non-blocking update later.
🧠 Conceptual
advanced2:00remaining
Difference in behavior of blocking vs non-blocking in combinational logic
Which statement best describes the recommended use of blocking and non-blocking assignments in combinational logic always blocks?
Attempts:
2 left
💡 Hint
Combinational logic needs immediate updates to simulate correctly.
✗ Incorrect
Blocking assignments are recommended in combinational always blocks because they update variables immediately, reflecting the combinational logic behavior without race conditions.
❓ Predict Output
expert2:00remaining
Final values after mixed blocking and non-blocking assignments
Given the following Verilog code executed on a posedge clk:
What are the values of a and b after the clock edge?
reg a = 0, b = 0; always @(posedge clk) begin a <= b + 1; b = a + 1; end
What are the values of a and b after the clock edge?
Verilog
reg a = 0, b = 0; always @(posedge clk) begin a <= b + 1; b = a + 1; end
Attempts:
2 left
💡 Hint
Remember that blocking assignments update immediately, non-blocking update later.
✗ Incorrect
b is assigned immediately with a+1 (a is 0 initially), so b=1. a is scheduled to be b+1 (old b=0), so a=1 after the block ends.