如何声明和在Verilog中使用的一维和二维字节数组? [英] How to declare and use 1D and 2D byte arrays in Verilog?
问题描述
如何声明和使用Verilog的一维和二维字节数组?
如。如何做这样的事情。
字节a_2D [3] [3];
字节a_1D [3];使用1D //
的for(int i = 0;我3;;我++)
{
a_1D [I] =(字节)I;
}使用二维//
的for(int i = 0;我3;;我++)
{
为(中间体J = 0; J&下; 3; J ++)
{
a_2D [I] [J] =(字节)我*焦耳;
}
}
的Verilog认为在位,因此 REG [7:0] A [0:3]
会给您有一个4×8位阵列(= 4X1字节数组)。你与获得的第一个字节出这一个[0]
。第2个字节的第三位 A [1] [2]
。
有关字节的二维数组,首先检查你的模拟器/编译器。旧版本(pre 01,我相信)不支持此功能。然后 REG [7:0] A [0:3] [0:3]
会给你一个字节二维数组。单个位可以用 A [2] [0] [7]
访问为例。
REG [7:0] A [0:3];
章第[7:0] B〔0:3] [0:3];REG [7:0℃;
章D组;最初的开始 的for(int i = 0; I< = 3;我++)开始
一个由[i] = I [7:0];
结束 C = A [0];
D = A [1] [2];
使用二维//
的for(int i = 0; I< = 3;我++)
对于(INT J = 0; J< = 3; J ++)
B〔I] [J] = I *焦耳; //看这个,如果你正在构建的硬件结束
How to declare and use 1D and 2D byte arrays in Verilog?
eg. how to do something like
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 thinks in bits, so reg [7:0] a[0:3]
will give you a 4x8 bit array (=4x1 byte array). You get the first byte out of this with a[0]
. The third bit of the 2nd byte is a[1][2]
.
For a 2D array of bytes, first check your simulator/compiler. Older versions (pre '01, I believe) won't support this. Then reg [7:0] a [0:3] [0:3]
will give you a 2D array of bytes. A single bit can be accessed with a[2][0][7]
for example.
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
这篇关于如何声明和在Verilog中使用的一维和二维字节数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!