0
0
Verilogprogramming~20 mins

Blocking vs non-blocking assignment in Verilog - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Verilog Assignment Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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
Aa=1, b=1, c=0
Ba=0, b=0, c=0
Ca=1, b=1, c=1
Da=1, b=0, c=0
Attempts:
2 left
💡 Hint
Blocking assignments execute in order and update variables immediately.
Predict Output
intermediate
2: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
Aa=1, b=0, c=0
Ba=1, b=1, c=1
Ca=0, b=0, c=0
Da=1, b=1, c=0
Attempts:
2 left
💡 Hint
Non-blocking assignments update variables only after the always block finishes.
🔧 Debug
advanced
2:00remaining
Identify the error in mixed blocking and non-blocking assignments
Consider this Verilog code inside an always block triggered by posedge clk:
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
AIt causes a race condition leading to unpredictable values.
BIt causes a syntax error due to mixing assignment types.
CIt works correctly and updates x and y as expected.
DIt causes a latch to be inferred by synthesis tools.
Attempts:
2 left
💡 Hint
Mixing blocking and non-blocking assignments in the same block can cause timing issues.
🧠 Conceptual
advanced
2: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?
AUse a mix of blocking and non-blocking assignments to optimize timing.
BUse non-blocking assignments (<=) because they schedule updates and prevent glitches.
CAvoid both blocking and non-blocking assignments; use continuous assignments instead.
DUse blocking assignments (=) because they update variables immediately and avoid race conditions.
Attempts:
2 left
💡 Hint
Combinational logic needs immediate updates to simulate correctly.
Predict Output
expert
2:00remaining
Final values after mixed blocking and non-blocking assignments
Given the following Verilog code executed on a posedge clk:
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
Aa=0, b=1
Ba=1, b=1
Ca=1, b=2
Da=2, b=1
Attempts:
2 left
💡 Hint
Remember that blocking assignments update immediately, non-blocking update later.