doubt on simple verilog program

Status
Not open for further replies.

mujju433

Full Member level 3
Joined
Jun 2, 2007
Messages
174
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,298
Activity points
2,293
module intra_assign();

reg a, b;
always
#2 b=0;
initial
begin
a = 1;
b = 0;
#4 a=0;
#6 a=1;
end
initial
$monitor("TIME = %d A = %d B = %d",$time, a , b);
initial
#20 $finish;
endmodule


Questions
1. Why for the above code the output is not displayed at 2ns,6ns, 8ns,12ns,14ns,16ns,18ns ? As far as I know that these blocks will be getting executed concurrently am I right?


TIME = 0 A = 1 B = 0
# TIME = 4 A = 0 B = 0
# TIME = 10 A = 1 B = 0
# ** Note: $finish : testbench.sv(25)
# Time: 20 ns Iteration: 0 Instance: /intra_assign




2nd program , output and then doubt

module intra_assign();

reg a, b;
always
#2 b= a;
initial
begin
a = 1;
b = 0;
#2 a=0;
#2 a=1;
end

initial
$monitor("TIME = %d A = %d B = %d",$time, a , b);
initial
#20 $finish;
endmodule

Output is shown

TIME = 0 A = 1 B = 0
# TIME = 2 A = 0 B = 1
# TIME = 4 A = 1 B = 0
# TIME = 6 A = 1 B = 1

Questions
1. At 2ns how the value of B=1? It should take the same value which is for A @ 2ns and assign to B but it is taking the value of a @ 0ns and displaying at the output Please clarify

2. The output is not finding the values for 8ns,10ns,12ns,14ns,16ns,18ns because all the blocks are concurrent and it has to go till all these ns, Since @20ns we are finishing the program. Please clarify



3rd Program:

module intra_assign();

reg a, b;
always
b= #2 a;
initial
begin
a = 1;
b = 0;
#2 a=0;
#2 a=1;
end

initial
$monitor("TIME = %d A = %d B = %d",$time, a , b);
initial
#20 $finish;
endmodule

Output:
TIME = 0 A = 1 B = 0
# TIME = 2 A = 0 B = x
# TIME = 4 A = 1 B = 1
# TIME = 6 A = 1 B = 0
# TIME = 8 A = 1 B = 1

Questions:

1.For 2 time units value of A=0 and B=x ( This X is because in the Always block we have given b=#2a; which means the value at 0ns will be sensed by a and assigned to b only after 2ns am i right so after 2ns can be considered as 3 or 4ns---If this statement is true then the concept would be correct please let me know if i am going in the right direction)---Please clarify

2. Why the Always block is not getting executed at 10ns,12ns,14ns,16ns,18ns ( Is it because there is no chance for a to sense the value at 6ns ( Is it because the initial block contains the time units 4ns)---Please clarify
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…