0
0
Verilogprogramming~20 mins

Always block sensitivity list in Verilog - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Always Block Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of always block with posedge clock sensitivity

What is the output of the following Verilog code snippet when the clock rises?

Verilog
module test;
  reg clk = 0;
  reg [3:0] count = 0;
  always @(posedge clk) begin
    count <= count + 1;
  end
  initial begin
    #1 clk = 1;
    #1 clk = 0;
    #1 clk = 1;
    #1 clk = 0;
    #1 $display("Count: %d", count);
    $finish;
  end
endmodule
ACount: 2
BCount: 3
CCount: 0
DCount: 1
Attempts:
2 left
💡 Hint

Count increments on each rising edge of clk.

Predict Output
intermediate
2:00remaining
Output of always block with negedge reset sensitivity

What will be the value of q after the following code runs?

Verilog
module test;
  reg rst_n = 1;
  reg clk = 0;
  reg q = 0;
  always @(posedge clk or negedge rst_n) begin
    if (!rst_n)
      q <= 0;
    else
      q <= 1;
  end
  initial begin
    #1 rst_n = 0;
    #1 rst_n = 1;
    #1 clk = 1;
    #1 clk = 0;
    #1 $display("q = %d", q);
    $finish;
  end
endmodule
Aq = 0
Bq = 1
Cq = x (unknown)
Dq = 2
Attempts:
2 left
💡 Hint

Reset is active low and asynchronous.

🔧 Debug
advanced
2:00remaining
Identify error in always block sensitivity list

Which option shows the correct sensitivity list for a combinational always block that depends on inputs a and b?

Verilog
always @(a or b) begin
  y = a & b;
end
Aalways @(posedge a or posedge b)
Balways @(a and b)
Calways @(a or b)
Dalways @(posedge a and posedge b)
Attempts:
2 left
💡 Hint

Combinational blocks use level sensitivity, not edge sensitivity.

📝 Syntax
advanced
2:00remaining
Syntax error in always block sensitivity list

Which option will cause a syntax error in the always block sensitivity list?

Aalways @(clk posedge or rst_n negedge)
Balways @(clk or rst_n)
Calways @(posedge clk or negedge rst_n)
Dalways @(posedge clk and negedge rst_n)
Attempts:
2 left
💡 Hint

Sensitivity list keywords must come before signal names.

🚀 Application
expert
2:00remaining
Number of triggers in always block sensitivity list

Given the following always block, how many times will it trigger during the simulation?

reg a = 0, b = 0, c = 0;
always @(a or b or c) begin
  // some logic
end
initial begin
  a = 1; b = 1; c = 1;
  #1 a = 0;
  #1 b = 0;
  #1 c = 0;
  #1 $finish;
end
A1
B4
C3
D6
Attempts:
2 left
💡 Hint

Count each change in a, b, and c that triggers the block.