该特定语法称为索引部分选择。当您需要从多位寄存器中的变量偏移量中选择固定数量的位时,它非常有用。
下面是语法的例子:
reg [31:0] dword;
reg [7:0] byte0;
reg [7:0] byte1;
reg [7:0] byte2;
reg [7:0] byte3;
assign byte0 = dword[0 +: 8]; // Same as dword[7:0]
assign byte1 = dword[8 +: 8]; // Same as dword[15:8]
assign byte2 = dword[16 +: 8]; // Same as dword[23:16]
assign byte3 = dword[24 +: 8]; // Same as dword[31:24]
与此语法的最大好处是,你可以使用一个变量的索引。正常器件在Verilog中选择需要常量。所以尝试使用dword[i+7:i]
之类的东西是不允许的。
所以,如果你想选择一个特定的字节使用变量选择,你可以使用索引部分选择。
实施例使用可变:
reg [31:0] dword;
reg [7:0] byte;
reg [1:0] i;
// This is illegal due to the variable i, even though the width is always 8 bits
assign byte = dword[(i*8)+7 : i*8]; // ** Not allowed!
// Use the indexed part select
assign byte = dword[i*8 +: 8];
我想你想在第二个例子中用'select'替换'i'。 – nguthrie