accessing bit in a Dynamic Array

D

Deepu

Guest
Hi All,

How can i access a bit in a dynamic array which is 16bit wide and
500000 depth

I tried as below:

reg [15:0] dynamic_array[];

// set the size
dynamic_array = new[500000];

// accessing a bit

num = 100000;

case(bit)
0: begin set = 1; dynamic_array[num][0] = 1; end
1: begin set = 1; dynamic_array[num][1] = 1; end
2: begin set = 1; dynamic_array[num][2] = 1; end
and so on till 15
14: begin set = 1; dynamic_array[num][3] = 1; end
15: begin set = 1; dynamic_array[num][4] = 1; end
endcase

But when i try to display it always gives 'x'. Is this a wrong way of
using? Is there any other better method if i have 'num' which is from
0 to 500000 and each num can have 16 bit value?

Thanks for the help!
 
On Wed, 2 Sep 2009 07:34:04 -0700 (PDT), Deepu wrote:

I tried as below:

reg [15:0] dynamic_array[];

// set the size
dynamic_array = new[500000];

// accessing a bit

num = 100000;

case(bit)
0: begin set = 1; dynamic_array[num][0] = 1; end
1: begin set = 1; dynamic_array[num][1] = 1; end
2: begin set = 1; dynamic_array[num][2] = 1; end
and so on till 15
14: begin set = 1; dynamic_array[num][3] = 1; end
15: begin set = 1; dynamic_array[num][4] = 1; end
endcase

But when i try to display it always gives 'x'.
I don't know what you mean by this.
Your code is illegal because "bit" is a SystemVerilog
keyword. Even if it were a variable name, I don't see
what your code is doing with that variable.


Here's the code I tried:

module da_bits;
reg [15:0] da[];
int num;
initial begin
da = new[500000];
num = 100000;
da[num][0] = 1;
$display("%b", da[num]);
$display("%b", da[num][0]);
end
endmodule

And the result I got was:

xxxxxxxxxxxxxxx1
1

Which, surely, is correct.

Is this a wrong way of using?
No, I don't think so. Maybe your display code is wrong?
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
On Wed, 2 Sep 2009 11:44:31 -0700 (PDT), Deepu wrote:

Can dynamic array be initialized inside the initial block?

initial
begin
for (i=0; i<500000; i=i+1)
begin
dynamic_array = 16'b0000000000000000;
end
end

Of course (but don't forget "new[]"!)
Why would you imagine it could not?

You may like this form even better:

initial begin
dynamic_array = new[500000];
foreach (dynamic_array)
dynamic_array = 0;
end

SystemVerilog may have its faults, but you
cannot criticise it for having too small
a collection of useful features :)
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
Thanks for your input!!

Can dynamic array be initialized inside the initial block?

initial
begin
for (i=0; i<500000; i=i+1)
begin
dynamic_array = 16'b0000000000000000;
end
end
 
On Sep 2, 7:34 pm, Deepu <pradeep...@gmail.com> wrote:
Hi All,

How can i access a bit in a dynamic array which is 16bit wide and
500000 depth

I tried as below:

reg [15:0] dynamic_array[];

// set the size
dynamic_array = new[500000];

// accessing a bit

num = 100000;

case(bit)
0: begin set = 1; dynamic_array[num][0] = 1; end
1: begin set = 1; dynamic_array[num][1] = 1; end
2: begin set = 1; dynamic_array[num][2] = 1; end
and so on till 15
14: begin set = 1; dynamic_array[num][3] = 1; end
15: begin set = 1; dynamic_array[num][4] = 1; end
endcase

But when i try to display it always gives 'x'. Is this  a wrong way of
using? Is there any other better method if i have 'num' which is from
0 to 500000 and each num can have 16 bit value?

Thanks for the help!
I have one doubt to ask
How did you compile the code,
since bit is a sv keyword
you seem to be getting till the point of display , that means it did
compile the code
can you name me the implementatino that you used
I mean whether you used VCS or some other compiler
 

Welcome to EDABoard.com

Sponsor

Back
Top