Challenge - 5 Problems
Blocking Assignment Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of combinational logic with blocking assignments
What is the output of the following Verilog code snippet when inputs a=1 and b=0?
Verilog
module test(input a, input b, output reg y); always @(*) begin y = a & b; y = y | a; end endmodule
Attempts:
2 left
💡 Hint
Remember blocking assignments (=) execute statements in order inside always blocks.
✗ Incorrect
The first assignment sets y = a & b = 1 & 0 = 0. The second assignment updates y = y | a = 0 | 1 = 1. So final y is 1.
❓ Predict Output
intermediate2:00remaining
Effect of blocking vs non-blocking in combinational logic
Given the following Verilog code, what is the value of y after execution if a=1 and b=0?
Verilog
module test(input a, input b, output reg y); always @(*) begin y <= a & b; y <= y | a; end endmodule
Attempts:
2 left
💡 Hint
Non-blocking assignments (<=) update variables at the end of the time step.
✗ Incorrect
The first assignment schedules y to 0. The second assignment overrides the schedule with old y | a, where old y is the previous value (unknown), resulting in y = x (unknown).
🧠 Conceptual
advanced2:00remaining
Why use blocking assignments for combinational logic?
Which reason best explains why blocking assignments (=) are preferred for combinational logic in Verilog?
Attempts:
2 left
💡 Hint
Think about how combinational logic works in hardware and how blocking assignments execute.
✗ Incorrect
Blocking assignments execute statements in order immediately, which matches how combinational logic computes outputs based on inputs without delay.
🔧 Debug
advanced2:00remaining
Identify the problem with using non-blocking assignments in combinational logic
What issue arises if non-blocking assignments (<=) are used inside a combinational always block?
Attempts:
2 left
💡 Hint
Consider when non-blocking assignments update variables during simulation.
✗ Incorrect
Non-blocking assignments update variables at the end of the time step, so outputs may not reflect input changes immediately, causing incorrect combinational simulation.
🚀 Application
expert3:00remaining
Determine the number of items in the resulting dictionary after combinational blocking assignments
Consider the following Verilog-like pseudocode representing combinational logic with blocking assignments:
always @(*) begin
for (int i = 0; i < 3; i++) begin
out[i] = in[i] & enable;
end
end
If in = {1,0,1} and enable = 1, how many elements in out will be 1 after execution?
Attempts:
2 left
💡 Hint
Check each bit of in ANDed with enable=1.
✗ Incorrect
out[0] = 1 & 1 = 1, out[1] = 0 & 1 = 0, out[2] = 1 & 1 = 1. So two elements are 1.