At the outset, I would like to say that I am not able to run this snippet at the moment but, even if I were, I hope this question would still stand as I'd like to understand why the Verilog standard implies a given interpretation of this snippet.
The snippet below is adapated from one seen in Chapter 8 of Saurabh's Introduction to VLSI Design Flow. It is written in 2001-Verilog but, I think, it works in modern simulators too.
module top();
reg a,b, clock;
initial begin
a = 1'b1;
b = 1'b0;
clock = 1'b0;
end
always clock = #10 ~clock; // clock with period 20 time units
always @(posedge clock) begin
a<= b; //a changes to 1'b0 at t=10 and 1'b1 at t=30 and so on...
b<= a; //b changes to 1'b1 at t=10 and 1'b0 at t=30 and so on...
end
endmodule
What I am confused about is the following: is this code guaranteed to work as intended given the comments below?
(1) In Verilog there is no guarantee that an initial block executes before an always block. This is up to the simulator.
(2) For intra-assignment delay (as in the clock updating always) the RHS is evaluated before the delay.
Given (1) and (2), it's not clear to me that this code is guaranteed to work. For example: if the always block is entered first, before the initial block, then, since clock has as yet not been intitialized I believe we will get clock toggled to x after 10 seconds, meaning that we do not get a positive edge of the clock at 10 seconds. On the other hand, if the initial is entered first then things work out as intended. Is this understanding correct?