my_adder是32位加法器,它的溢出是1位。 但adder_array中的溢出是4位。我该怎么解决这个问题?
module adder_array(
cmd,
ain0, ain1, ain2, ain3,
bin0, bin1, bin2, bin3,
dout0, dout1, dout2, dout3,
overflow);
input [2:0] cmd;
input [31:0] ain0, ain1, ain2, ain3;
input [31:0] bin0, bin1, bin2, bin3;
output reg [31:0] dout0, dout1, dout2, dout3;
output [3:0] overflow;
wire [31:0] a[3:0];
wire [31:0] b[3:0];
wire [31:0] d[3:0];
wire ovf[3:0];
assign {a[0],a[1],a[2],a[3]} = {ain0,ain1,ain2,ain3};
assign {b[0],b[1],b[2],b[3]} = {bin0,bin1,bin2,bin3};
assign {d[0],d[1],d[2],d[3]} = {dout0, dout1, dout2, dout3};
parameter size = 4;
genvar i;
generate for(i = 0 ; i < size - 1 ; i = i + 1)
begin: adder
if (i == 0) begin
my_add(.ain(a[0]), .bin(b[0]), .dout(d[0]), .overflow(ovf[0]));
end
else if (i == size - 1 ) begin
my_add(.ain(a[i]), .bin(b[i]), .dout(d[i]), .overflow(ovf[i]));
end
else begin
my_add(.ain(a[i]), .bin(b[i]), .dout(d[i]), .overflow(ovf[i]));
end
end
endgenerate
assign overflow = {ovf[3], ovf[2], ovf[1], ovf[0]};
always @(cmd) begin
case(cmd)
3'b000 : begin dout0 = d[0]; dout1 = 0; dout2 = 0; dout3 = 0; end
3'b001 : begin dout0 = 0; dout1 = d[1]; dout2 = 0; dout3 = 0; end
3'b010 : begin dout0 = 0; dout1 = 0; dout2 = d[2]; dout3 = 0; end
3'b011 : begin dout0 = 0; dout1 = 0; dout2 = 0; dout3 = d[3]; end
3'b100 : begin dout0 = d[0]; dout1 = d[1]; dout2 = d[2]; dout3 = d[3]; end
endcase
end
endmodule
答案 0 :(得分:0)
错误信息非常清楚。模块实例如下:
my_add(.ain(a[0]), .bin(b[0]), .dout(d[0]), .overflow(ovf[0]));
需要实例名称,例如
my_add my_add0 (.ain(a[0]), .bin(b[0]), .dout(d[0]), .overflow(ovf[0]));
^^^^^^^
Verilog中的模块实例必须始终具有实例名称。实例名称就像电路图上的标签。在电路图中,您将IC标记为IC1,IC2等,将电容标记为C1,C2等。您需要在Verilog中做同样的事情。并且,就像在电路图上一样,实例名称在特定范围内(即在模块内)必须是唯一的。类比的电路图仍然是:你不会在电路图上有两个IC1或两个C1吗?