Consider the following Verilog code snippet. What will be the order and timing of the printed messages?
module test;
initial begin
$display("Start at time %0t", $time);
#5 $display("After 5 time units at %0t", $time);
#3 $display("After 8 time units at %0t", $time);
end
endmoduleRemember that delays accumulate in sequence inside an initial block.
The first $display runs at time 0. Then #5 delays 5 units, so the second $display runs at time 5. Then #3 delays 3 more units, so the third $display runs at time 8.
Analyze the following Verilog code. What is the final value of count after the initial block completes?
module test; integer count = 0; initial begin count = 1; #10 count = count + 1; #5 count = count + 2; end endmodule
Delays add up and assignments happen after each delay.
Initially count=0, then set to 1 immediately. After 10 time units, count=2. After 5 more time units (total 15), count=4.
Given these Verilog snippets using #delay, which one will cause a simulation time to not advance as expected or cause a runtime issue?
Check if negative delays are allowed in Verilog simulation.
Negative delays like #(-5) are illegal and cause simulation errors. Zero or positive delays are valid.
Consider two initial blocks running concurrently with different #delays. Which statement is true about their execution?
Think about concurrency and how delays work per process.
Each initial block is a separate process. Delays only pause that process, not others.
Analyze the following Verilog code. What will be printed and at what simulation times?
module test;
initial begin
$display("Start at %0t", $time);
fork
begin
#3 $display("Fork 1 at %0t", $time);
#2 $display("Fork 1 later at %0t", $time);
end
begin
#1 $display("Fork 2 at %0t", $time);
#4 $display("Fork 2 later at %0t", $time);
end
join
$display("End at %0t", $time);
end
endmoduleRemember fork-join waits for all forked blocks to finish before continuing.
Start prints at 0. Fork 2 prints at 1, Fork 1 at 3. Then Fork 1 later and Fork 2 later both print at 5. join waits until time 5. End prints at 5.
