module median_five(out1,a[0],a[1],a[2],a[3],a[4],en,clka);
input [7:0] a[0:4];
output out1;
endmodule
**它给出错误。
module median_five(out1,a,b,c,d,e,en,clka);
input [7:0] a,b,c,d,e;
output out1;
endmodule
**这是正确的。
但我想在数组中输入 a、b、c、d、e,如:
array[0]<=a;
array[1]<=b;
array[2]<=c;
array[3]<=d;
array[4]<=e;
最佳答案
Verilog 不支持二维数组作为模块的端口。 支持此功能SystemVerilog 只要。
在 第一个 片段,您正在传递 二维数组 a
作为输入,不支持。在 后者案例,一个 一维向量 被传递给工作正常的模块。
不清楚你想用 array
做什么.这里有一些 选项 .您可以在模块内声明二维数组本身。如下所示:
module median_five(out1,a,b,c,d,e,en,clka);
input [7:0] a,b,c,d,e;
output out1;
ref [7:0] array [5]; // array local to module
//always @(posedge clka) // use non blocking assignments
always @(*) // use blocking assignments
begin
// .. Some stuff
array[0]=a;
array[1]=b;
array[2]=c;
array[3]=d;
array[4]=e;
//..
end
//.. some other stuff
endmodule
你可以做的另一件事是展平阵列 并将其作为输入传递。在这里,我已经扁平化了每个 8 位输入 (
a
、b
、c
等每个)转换为 单向量 ( in
) 并分配给每个 数组的单个元素 因此。module top (in, out);
input [31:0] in; // flattened array as input
output [31:0] out;
wire [7:0] array [0:3]; // local array
assign {array[3],array[2],array[1],array[0]} = in;
//... some operations/procedural blocks etc.
assign out = {array[3],array[2],array[1],array[0]};
endmodule
引用 Inputs as two dimensional array类似问题的链接。有一个similar blog post也。
关于verilog - 是否可以在verilog中将输入端口作为数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36370438/