T
Taras_96
Guest
Hi all,
I was going through this verilog example, and I was wondering if
anyone could explain it to me. It concerns the varying types of
assignments that can be done in verilog:
module delay; //1
reg a,b,c,d,e,f,g,bds,bsd; //2
initial begin //3
a = 1; b = 0; // No delay control. //4
#1 b = 1; // Delayed assignment. //5
c = #1 1; // Intra-assignment delay. //6
#1; // Delay control. //7
d = 1; // //8
e <= #1 1; // Intra-assignment delay, nonblocking assignment //9
#1 f <= 1; // Delayed nonblocking assignment. //10
g <= 1; // Nonblocking assignment. //11
end //12
initial begin
#1 bds = b;
end // Delay then sample (ds). //13
initial begin
bsd = #1 b;
end // Sample then delay (sd). //14
initial begin
$display("t a b c d e f g bds bsd"); //15
$monitor("%g",$time,,a,,b,,c,,d,,e,,f,,g,,bds,,,,bsd);
end //16
endmodule //17
OUTPUT:
t a b c d e f g bds bsd
0 1 0 x x x x x x x
1 1 1 x x x x x 1 0
2 1 1 1 x x x x 1 0
3 1 1 1 1 x x x 1 0
4 1 1 1 1 1 1 1 1 0
I tried explaining the results by myself:
t = 0.
Events:
1 assigned to a
0 assigned to b
Scheduled:
b is scheduled to be assigned to 1
bds is scheduled to be assigned the value of b
bsd is scheduled to be assigned the value of current b (0)
t = 1.
Execution of scheduled events:
b is assigned one
bds is assigned one (isn't this a race condition??) *
bsd is assigned 0
Events:
Scheduled:
c is scheduled to be assigned 1
t = 2:
Execution of sheduled events:
c is assigned one
Event:
encounters #1
t = 3:
Events:
d is assigned one
don't know about the rest of the statements **
QUESTION ONE (*)
wouldn't the statements on lines 5 and 13 create a race condition? IE:
for t = 1, b must be assigned one and also bsd = b. Now if bsd = b is
executed first, then bsd = 0 (since b = 1 hasn't been executed yet).
Alternatively, if b = 1 is executed first, wouldn't bsd = b result in
bsd = 1?
QUESTION TWO (**)
I'm not exactly sure what happens at t = 3. During this time, d is
assigned one. Why does the change forced by g <= 1 not show up until
t = 4? What is the difference between the three non-blocking
assignments (lines 9,10,11)? They all seem to have the same result...
How does the scheduler 'read' the three statements?
Any help would be greatly appreciated.
Cheers
Taras
I was going through this verilog example, and I was wondering if
anyone could explain it to me. It concerns the varying types of
assignments that can be done in verilog:
module delay; //1
reg a,b,c,d,e,f,g,bds,bsd; //2
initial begin //3
a = 1; b = 0; // No delay control. //4
#1 b = 1; // Delayed assignment. //5
c = #1 1; // Intra-assignment delay. //6
#1; // Delay control. //7
d = 1; // //8
e <= #1 1; // Intra-assignment delay, nonblocking assignment //9
#1 f <= 1; // Delayed nonblocking assignment. //10
g <= 1; // Nonblocking assignment. //11
end //12
initial begin
#1 bds = b;
end // Delay then sample (ds). //13
initial begin
bsd = #1 b;
end // Sample then delay (sd). //14
initial begin
$display("t a b c d e f g bds bsd"); //15
$monitor("%g",$time,,a,,b,,c,,d,,e,,f,,g,,bds,,,,bsd);
end //16
endmodule //17
OUTPUT:
t a b c d e f g bds bsd
0 1 0 x x x x x x x
1 1 1 x x x x x 1 0
2 1 1 1 x x x x 1 0
3 1 1 1 1 x x x 1 0
4 1 1 1 1 1 1 1 1 0
I tried explaining the results by myself:
t = 0.
Events:
1 assigned to a
0 assigned to b
Scheduled:
b is scheduled to be assigned to 1
bds is scheduled to be assigned the value of b
bsd is scheduled to be assigned the value of current b (0)
t = 1.
Execution of scheduled events:
b is assigned one
bds is assigned one (isn't this a race condition??) *
bsd is assigned 0
Events:
Scheduled:
c is scheduled to be assigned 1
t = 2:
Execution of sheduled events:
c is assigned one
Event:
encounters #1
t = 3:
Events:
d is assigned one
don't know about the rest of the statements **
QUESTION ONE (*)
wouldn't the statements on lines 5 and 13 create a race condition? IE:
for t = 1, b must be assigned one and also bsd = b. Now if bsd = b is
executed first, then bsd = 0 (since b = 1 hasn't been executed yet).
Alternatively, if b = 1 is executed first, wouldn't bsd = b result in
bsd = 1?
QUESTION TWO (**)
I'm not exactly sure what happens at t = 3. During this time, d is
assigned one. Why does the change forced by g <= 1 not show up until
t = 4? What is the difference between the three non-blocking
assignments (lines 9,10,11)? They all seem to have the same result...
How does the scheduler 'read' the three statements?
Any help would be greatly appreciated.
Cheers
Taras