我正在为左移寄存器编写 Verilog 代码,该寄存器在每次移位后将其值存储在子寄存器中。我可以将输出寄存器定义为这样的数组吗?提供的代码只是一个简单的例子来展示这个概念,而不是我的代码:
module test(a,b,c);
input a,b;
output [7:0] c [3:0];
endmodule
代替
module test(a,b,c1,c2,c3,c4);
input a,b;
output [7:0] c1,c2,c3,c4;
endmodule
对于第一种方式,我如何调用
c[i]
?
是的,您可以在输出中使用二维数组,就像您的第一个示例一样。查看 Stuart Sutherland 撰写的这篇论文的第 5 部分;这应该会给你一些信心。该部分的标题为
Module Ports
.
另外,详细说明你的第一个例子,为了清楚起见,你可以这样定义你的模块:
module lshift(clk, reset, a, c);
input wire clk, reset;
input wire [7:0] a;
output reg [7:0] c [0:3]; // <-- defining the unpacked dimension as [0:3] for clarity
always@(posedge clk) begin
if(reset) begin
c[0] <= 8'd0;
...
c[3] <= 8'd0;
end
else begin
c[0] <= a;
c[1] <= c[0];
c[2] <= c[1];
c[3] <= c[2];
end
end
endmodule
...现在你可以切入你的数组。
c[0], c[1] .. c[3]
每个代表一个字节,c[0][3:0]
表示第一个字节的低半字节。