Home > Enterprise >  Packed array declaration in system verilog
Packed array declaration in system verilog

Time:08-26

I came across the below syntax while declaring the packed array .

bit arr [bit[3:0];

My understanding is, Depth of this arr is 16 and width is 1 bit. But When i try printing the values using the below loop, it doesn't print anything :

foreach(arr[ii])
    $display("arr[
] = 
",ii,arr[ii]);

Also, I can able to write & read to any of the indexes like arr[56] = 1 and able to print the same as well without any errors.

Can someone please explain the logic behind this ?

CodePudding user response:

This is an unpacked associative array whose elements are a single bit, and the the index(key) type is a packed array of 4-bits.

Associative array elements do not get allocated until you make an assignment to a particular key index. So the foreach loop will not iterate until there are allocated elements.

  • Related