ch2-Unpacked array

2019-10-24

Multidimensional Unpacked Array

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
module tb;
byte stack [2][4]; // 2 rows, 4 cols

initial begin
// 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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module tb;
bit [3:0][7:0] stack [2][4]; // 2 rows, 4 cols

initial begin
// 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


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!