Study the following shift-register stage and testbench stimulus: timescal…
Study the following shift-register stage and testbench stimulus: timescale 1ns/1ps module pipe_sim; reg clk; reg d; reg q1, q2; initial begin clk = 0; forever #5 clk = ~clk; end initial begin d = 1'b0; @(posedge clk); #0 d = 1'b1; @(posedge clk); d = 1'b0; #20 $finish; end always @(posedge clk) begin q1 <= d; q2 <= q1; end endmodule Clock period is 10 ns (edges at t = 5, 15, 25, 35 ns ). At what simulation time does q2 first transition from 1'b0 to 1'b1 ?
- At $t = 5 ns$
- At $t = 15 ns$
- At $t = 25 ns$
- At $t = 35 ns$
Correct answer
C. At $t = 25 ns$
Explanation
Trace each simulation event through the delta-cycle execution: 1. **$t = 5 ns$ (1st posedge clk ):** * The @(posedge clk) statement unblocks in the testbench. * In the always block, q1 <= d and q2 <= q1 schedule updates. At this instant, d = 0 and q1 = 0 . * Both q1 and q2 remain 0 . * Testbench executes #0 d = 1'b1; . This delays d to the Inactive region of $t = 5 ns$. Thus, d becomes 1 *after* the active clock evaluation at $t = 5 ns$ has already read d = 0 . 2. **$t = 15 ns$ (2nd posedge clk ):** * Active region evaluates RHS: d is currently 1 , and q1 is currently 0 . * Scheduled in NBA: q1 <= 1 , q2 <= 0 . * NBA update phase: q1 transitions to 1 ; q2 remains 0 . * Testbench assigns d = 0 . 3. **$t = 25 ns$ (3rd posedge clk ):** * Active region evaluates RHS: d is 0 , and q1 is 1 . * Scheduled in NBA: q1 <= 0 , q2 <= 1 . * NBA update phase: q1 transitions to 0 ; ** q2 transitions to 1** . Therefore, q2 first becomes 1 at **$t = 25 ns$**.