如何定义m*n输出?

问题描述 投票:0回答:1

我正在为左移寄存器编写 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]

verilog system-verilog
1个回答
2
投票

是的,您可以在输出中使用二维数组,就像您的第一个示例一样。查看 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]
表示第一个字节的低半字节。

© www.soinside.com 2019 - 2024. All rights reserved.