英文:
In $readmemh command, how to specify to read from a starting address to ending address
问题
我有一个 360x640 的矩阵,即 230,400 个像素值。使用 $readmemh
,我想读取矩阵的特定部分并将其存储在矩阵 Y_luma
中(仅读取正方形框内的 8x8 矩阵值,即从 154 到 148 并存储在 Y_luma
矩阵的第一行,从 152 到 153 存储在 Y_luma
矩阵的第二行,以此类推,直到从 155 到 152 存储在 Y_luma
的第八行)。
我尝试的代码是:
module matrix_copy;
reg [7:0] Y_luma [0:7][0:7];
$readmemh("Luma_space.txt", Y_luma,
接下来的步骤不清楚。如何指定起始地址,即 [8][8]
,以及结束地址,即 [8][15]
在 Y_luma
的第一行,以及如何将下一个数组从 [9][8]
到 [9][15]
存储在 Y_luma
的第二行,以此类推?
帮助将不胜感激!
英文:
I have a 360x640 matrix i.e. 230,400 pixel values. Using $readmemh
, I want to read only a specific part of matrix and store it in matrix Y_luma
(read only the 8x8 matrix values inside the square box i.e. from 154 to 148 and store it in first row of matrix Y_luma
, from 152 to 153 store in 2nd row of matrix Y_luma
and so on until 155 to 152 in 8th row of Y_luma
).
The code I tried is:
module matrix_copy;
reg [7:0] Y_luma [0:7][0:7];
$readmemh("Luma_space.txt", Y_luma,
Not able to proceed afterwards. How to specify the start address i.e. [8][8] and stop address i.e. [8][15] in first row of matrix Y_luma
and also, how to store the next array from [9][8] to [9][15] in 2nd row of matrix Y_luma
and so on?
Help is appreciated!
答案1
得分: 1
以下是翻译好的部分:
一种方法是声明另一个内存变量,其大小与输入文件的大小完全匹配,并将整个文件读入该内存(地址范围为0至230,399)。然后,您可以使用 for
循环有选择地加载您的 Y_luma
变量。
reg [7:0] mem [360*640];
initial $readmemh("Luma_space.txt", mem);
这可以避免有关内存大小不正确的错误或警告消息。
还可以参考 IEEE Std 1800-2017,第21.4.3节“多维未打包数组的文件格式考虑”。但这可能要求您的输入文件采用非常特定的格式,可能包含地址条目(@0
)。
$readmemh
函数确实具有可选的 start_addr
和 finish_addr
参数,但要使它们与您的配置一起正常工作可能有点棘手。
这是一个可选参数的示例。
英文:
One approach is to declare another memory variable which exactly matches the size of the input file and read the entire file into that memory (addresses 0 to 230,399). Then you can use for
loops to selectively load your Y_luma
variable.
reg [7:0] mem [360*640];
initial $readmemh("Luma_space.txt", mem);
This avoids any error or warning messages about incorrect memory size.
Also refer to IEEE Std 1800-2017, section 21.4.3 File format considerations for multidimensional unpacked arrays. However, it might require that your input file be in a very specific format, perhaps with address entries (@0
).
$readmemh
does have optional start_addr
and finish_addr
arguments, but it might be tricky getting them to work with your configuration.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论