<- Click here to Toggle

Home » Resources » System Tasks & Functions » System Functions - Miscelleneous

Multi-Dimensional Unpacked Arrays

File format considerations for multi-dimensional unpacked arrays

In SystemVerilog, $readmemb, $readmemh, $writememb and $writememh can work with multi-dimensional unpacked arrays.

There is a hierarchical sense to the file data.

The higher dimensions contain words of lowerdimension data, sorted in row-major order. Each successive lower dimension is entirely enclosed as part of higher dimension words.

As an example of file format organization, here is the layout of a file representing words for a memory declared:

Example 1 :
reg [31:0] mem [0:1][0:2][5:8];
In the example word contents, wzyx,
— z corresponds to words of the [0:1] dimension
— y corresponds to words of the [0:2] dimension
— x corresponds to words of the [5:7] dimension
w005 w006 w007
w015 w016 w017
w025 w026 w027
w105 w106 w107
w115 w116 w117
w125 w126 w127

Example 2:
reg [31:0] mem [1:0][0:2][7:5]
@0 w005 w006 w007
w015 w016 w017
w025 w026 w027
@1 w105 w106 w107
w115 w116 w117
w125 w126 w127

System task arguments for multi-dimensional unpacked arrays

The $readmemb, $readmemh, $writememb, and $writememh signatures are shown below:

$readmemb("file_name", memory_name[, start_addr[, finish_addr]]);

$readmemh("file_name", memory_name[, start_addr[, finish_addr]]);

$writememb("file_name", memory_name[, start_addr[, finish_addr]]);

$writememh("file_name", memory_name[, start_addr[, finish_addr]]);

memory_name can be an unpacked array, or a partially indexed multi-dimensional unpacked array that resolves to a lesser-dimensioned unpacked array. Higher order dimensions must be specified with an index. The lowest dimension can be specified with slice syntax.

The start_addr and finish_addr arguments apply to the addresses of the unpacked array selected by memory_name. This address range represents the highest dimension of data in the file_name.

When slice syntax is used in the memory_name argument, any start_addr and finish_addr arguments must fall within the bounds of the slice’s range.