I have been reading on the unpacked and packed arrays in SV. I have mostly understood the concepts and style with which arrays are declared. However, there are some particular cases:
reg [8:0] stack [2][4]
here is my similar code :
module tb;
reg [8:0] stack [2][4] ;
initial begin
int i,j ;
foreach (stack[i])
foreach (stack[i][j]) begin
stack[i][j] = $random;
$display("stack[%0d][%0d] = 0x%0h" , i, j, stack[i][j]);
end
$display("stack = %p" , stack) ;
$display("stack[0][0][2] = 0x%0h" , stack[0][0][2]);
end
endmodule
Since there is only one dimension in the packed side before variable name, how do you explain the structure of this memory. How is it being arranged in terms of width x height x depth, or rows x columns?
Also, what does the stack[1][0][8]
return in both of the above cases? Stack is taking random values here, I only want to know what bunch of bits will stack[1][0][8]
output.
Currently, I don't have access to an IDE, but when I do, I will run these codes myself for better understanding.
here is my vcs output :
Compiler version S-2021.09; Runtime version S-2021.09; Oct 21 10:16 2022
stack[0][0] = 0x124
stack[0][1] = 0x81
stack[0][2] = 0x9
stack[0][3] = 0x63
stack[1][0] = 0x10d
stack[1][1] = 0x18d
stack[1][2] = 0x65
stack[1][3] = 0x12
stack = '{'{'h124, 'h81, 'h9, 'h63}, '{'h10d, 'h18d, 'h65, 'h12}}
stack[0][0][2] = 0x1