#910 Multi-dimensional array indexing error

devel
closed-fixed
6
2012-11-01
2012-10-30
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

  • Martin Whitaker

    Martin Whitaker - 2012-10-30

    Regression test for test suite

     
  • Martin Whitaker

    Martin Whitaker - 2012-11-01
    • assigned_to: nobody --> martinwhitaker
     
  • Martin Whitaker

    Martin Whitaker - 2012-11-01
    • status: open --> closed-fixed
     
  • Martin Whitaker

    Martin Whitaker - 2012-11-01

    Patch submitted to patch tracker.

     

Log in to post a comment.