Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#910 Multi-dimensional array indexing error

devel
closed-fixed
6
2012-11-01
2012-10-30
Martin Whitaker
No

The following code fragment

reg [7:0] Data[0:3][0:15];

integer i;
integer j;

initial begin
for (i = 0; i < 4; i = i + 1) begin
for (j = 0; j < 16; j = j + 1) begin
Data[i][j] = j;
end
end
for (j = 0; j < 16; j = j + 1) begin
$display("%h", Data[0][j]);
end
end

generates the output

00
01
02
03
04
05
06
07
00
01
02
03
04
05
06
07

The problem seems to be that when using the literal 0 as the major index, insufficient bits are used to calculate the offset into the array. The problem can be worked round by using an intermediate variable, e.g.

i = 0;
for (j = 0; j < 16; j = j + 1) begin
$display("%h", Data[i][j]);
end

A more complete test suitable for inclusion in the test suite is attached.

I will probably look at this later in the week unless anyone beats me to it.

Discussion

  • Regression test for test suite

     
    Attachments
    • assigned_to: nobody --> martinwhitaker
     
    • status: open --> closed-fixed
     
  • Patch submitted to patch tracker.