gpt4 book ai didi

arrays - 如何在 Verilog 中声明和使用一维和二维字节数组?

转载 作者:行者123 更新时间:2023-12-03 07:56:09 26 4
gpt4 key购买 nike

如何在 Verilog 中声明和使用一维和二维字节数组?

例如。如何做类似的事情

byte a_2D[3][3];
byte a_1D[3];

// using 1D
for (int i=0; i< 3; i++)
{
a_1D[i] = (byte)i;
}

// using 2D
for (int i=0; i< 3; i++)
{
for (int j=0; j< 3; j++)
{
a_2D[i][j] = (byte)i*j;
}
}

最佳答案

Verilog 以位为单位,所以 reg [7:0] a[0:3]会给你一个 4x8 位数组(=4x1 字节数组)。你用 a[0] 得到第一个字节.第二个字节的第三位是 a[1][2] .

对于二维字节数组,首先检查您的模拟器/编译器。旧版本(我相信 '01 之前的版本)不支持此功能。然后reg [7:0] a [0:3] [0:3]会给你一个二维字节数组。可以使用 a[2][0][7] 访问单个位例如。

reg [7:0] a [0:3];
reg [7:0] b [0:3] [0:3];

reg [7:0] c;
reg d;

initial begin

for (int i=0; i<=3; i++) begin
a[i] = i[7:0];
end

c = a[0];
d = a[1][2];


// using 2D
for (int i=0; i<=3; i++)
for (int j=0; j<=3; j++)
b[i][j] = i*j; // watch this if you're building hardware

end

关于arrays - 如何在 Verilog 中声明和使用一维和二维字节数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3011510/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com