initialbegin // Assign random values to each slot of the stack foreach (stack[i]) foreach (stack[i][j]) begin stack[i][j] = $random; $display ("stack[%0d][%0d] = 0x%0h", i, j, stack[i][j]); end
// Print contents of the stack $display ("stack = %p", stack); end endmodule
Packed + Unpacked Array
The example shown below illustrates a multidimensional packed + unpacked array.
initialbegin // Assign random values to each slot of the stack foreach (stack[i]) foreach (stack[i][j]) begin stack[i][j] = $random; $display ("stack[%0d][%0d] = 0x%0h", i, j, stack[i][j]); end
// Print contents of the stack $display ("stack = %p", stack);
// Print content of a given index $display("stack[0][0][2] = 0x%0h", stack[0][0][2]); end endmodule
In a multidimensional declaration, the dimensions declared before the name vary more faster than the dimensions following the name.
1 2 3 4 5 6
bit [1:4] m_var [1:5] // 1:4 varies faster than 1:5 bit m_var2 [1:5] [1:3] // 1:3 varies faster than 1:5 bit [1:3] [1:7] m_var3; // 1:7 varies faster than 1:3
bit [1:3] [1:2] m_var4 [1:7] [0:2] // 1:2 varies most rapidly, followed by 1:3, then 0:2 and then 1:7