如何在verilog中定义m * n输出

时间:2012-11-05 21:47:41

标签: verilog system-verilog

我正在写一个移位左寄存器的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]

的第一种方式

1 个答案:

答案 0 :(得分:1)

...是的,您可以在输出中使用2D数组,就像在第一个示例中一样。查看Stuart Sutherland本人的第5部分,这应该给你一些信心。该部分标题为Module Ports

http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CC4QFjAA&url=http%3A%2F%2Fwww.sutherland-hdl.com%2Fpapers%2F2006-SNUG-Europe_SystemVerilog_synthesis_paper.pdf&ei=7KmYUNKPN6GyigKDnoHwDA&usg=AFQjCNGmr3flHrARC-w40xveo8zitcdjfg&cad=rja

另外,详细说明您的第一个示例,您可以通过这种方式定义模块,以便清晰起见:

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]代表第一个字节的低半字节。

...希望这有帮助!

相关问题