Hello!
I’m trying to put and get the data into a mailbox, pretty basic stuff that I’m struggling with. So, here’s the code:
module mailbox_eg;
int i;
mailbox mbx;
initial begin
mbx = new(); //declaration and istantiation of mailbox mbx
fork
begin
$display("\n--------------Sending data----------------");
#1; //to start receiving the data from 1 ns
for (i=1;i<=5;i++)
begin: P1
mbx.put(i);
$display("\ndata sent = %0d at time = %0dns",mbx,$time);
#1;
end: P1
$display("\n-----------------Receiving data----------------");
begin: P2
for(i=1;i<=5;i++)
begin
mbx.get(i);
$display("\ndata received = %0d at time = %0dns",mbx,$time);
#1;
end
end: P2
end
join
end
endmodule
The O/P I was expecting was:
--------------Sending data----------------
#
# data sent = 1 at time = 1ns
#
# data sent = 2 at time = 2ns
#
# data sent = 3 at time = 3ns
#
# data sent = 4 at time = 4ns
#
# data sent = 5 at time = 5ns
#
# -----------------Receiving data----------------
#
# data received = 1 at time = 6ns
#
# data received = 2 at time = 7ns
#
# data received = 3 at time = 8ns
#
# data received = 4 at time = 9ns
#
# data received = 5 at time = 10ns
But the O/P I received is:
--------------Sending data----------------
#
# data sent = 65538 at time = 1ns
#
# data sent = 65538 at time = 2ns
#
# data sent = 65538 at time = 3ns
#
# data sent = 65538 at time = 4ns
#
# data sent = 65538 at time = 5ns
#
# -----------------Receiving data----------------
#
# data received = 65538 at time = 6ns
#
# data received = 65538 at time = 7ns
#
# data received = 65538 at time = 8ns
#
# data received = 65538 at time = 9ns
#
# data received = 65538 at time = 10ns
What do I do?
Thanks in advance!