What is the output of the following Verilog code snippet when the clock rises?
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
Count increments on each rising edge of clk.
The always block triggers on posedge clk. The clock rises twice, so count increments twice from 0 to 2.
What will be the value of q after the following code runs?
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
Reset is active low and asynchronous.
Reset is asserted low, setting q to 0. Then reset deasserts and clock rises, setting q to 1.
Which option shows the correct sensitivity list for a combinational always block that depends on inputs a and b?
always @(a or b) begin
y = a & b;
endCombinational blocks use level sensitivity, not edge sensitivity.
Combinational always blocks must list signals with 'or' to trigger on any change. Edge sensitivity (posedge/negedge) is for sequential logic.
Which option will cause a syntax error in the always block sensitivity list?
Sensitivity list keywords must come before signal names.
Option A reverses the order: 'clk posedge' is invalid syntax. The correct form is 'posedge clk'.
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
Count each change in a, b, and c that triggers the block.
The block triggers on any change of a, b, or c. Initial assignments change all three (3 triggers), then each #1 step changes one signal (3 more triggers), total 6.