I am trying to write a testbench for systemverilog module and I realized a strange behaviour depending on order of the always begin and initial begin block. Here is my code block which works correctly.
top test(clk, reset, writedata, dataadr, pc, instr, readdata, memwrite);
always begin
reset = 0;
clk = 0;
#10;
reset = 0;
clk = 1;
#10;
end
initial begin
clk = 0;
reset = 1; #10;
end
If the always begin block written before the initial begin block the code works perfectly fine and outputs this
But if we change the order of the always begin and initial begin blocks
top test(clk, reset, writedata, dataadr, pc, instr, readdata, memwrite);
initial begin
clk = 0;
reset = 1; #10;
end
always begin
reset = 0;
clk = 0;
#10;
reset = 0;
clk = 1;
#10;
end
In which the values are set to undetermined. Don't these two blocks work independently? Why does their order of writing cause a problem here?