Why do we need always blocks in Verilog designs?
Think about how hardware reacts to inputs and changes over time.
always blocks let you describe how signals update when inputs change, modeling hardware behavior that reacts continuously.
What is the value of q after the following Verilog code runs with clk toggling?
reg q = 0;
always @(posedge clk) begin
q <= ~q;
endConsider what happens on each rising edge of the clock.
The always @(posedge clk) block toggles q on every rising edge, so q flips between 0 and 1.
What happens if you try to assign a signal inside a module without using an always block or continuous assignment?
reg a; initial begin a = 1; a = 0; end
Think about what initial blocks do compared to always blocks.
initial blocks run once at the start of simulation, so a changes only at the beginning and then stays fixed.
Which statement best explains why always blocks are preferred over assign statements for describing sequential logic?
Think about how sequential logic depends on clock edges.
always blocks can trigger on clock edges to model sequential logic, while assign statements continuously drive signals for combinational logic.
What error will this Verilog code produce?
always @(posedge clk) begin if (reset == 1) q <= 0; else q <= q + 1; end
Check the types of assignments used inside the always block.
Using blocking (=) and non-blocking (<=) assignments together in the same always block can cause unexpected simulation behavior.