VerilogHDL - 将Array与非Array表达式连接时出错

时间:2015-01-25 02:18:08

标签: arrays verilog hdl

我正在努力使用我的代码,这是一个Carry-Save Multiplier。

module csm (A,B,So,Co);

parameter n = 8, m = 16;
input [7 : 0] A,B;
output [m-1 : 0] So;
output Co; // carry out

wire [7:0] CARRY [7:0];
reg [8:0] SUM [8:0];

assign So = {SUM[7][7],SUM[6][7],SUM[5][7],SUM[4][7],SUM[3][7], SUM[2][7],SUM[1][7],SUM[0][7],SUM[0][6],SUM[0][5],SUM[0][4],SUM[0][3],SUM[0][2],SUM[0][1],SUM[0][0]};

genvar i, j;
// Assign Carry out to the last carry related w/ overflow
assign Co = CARRY[7][7];
// Assign A[n] to SUM
//assign SUM[i][j] = {A[i],B[j]};
always@(*)
begin
 SUM[0][0] <= A[0];
 SUM[1][0] <= A[1];
 SUM[2][0] <= A[2];
 SUM[3][0] <= A[3];
 SUM[4][0] <= A[4];
 SUM[5][0] <= A[5];
 SUM[6][0] <= A[6];
 SUM[7][0] <= A[7];
 SUM[7][1] <= A[7];
 SUM[7][2] <= A[7];
 SUM[7][3] <= A[7];
 SUM[7][4] <= A[7];
 SUM[7][5] <= A[7];
 SUM[7][6] <= A[7];
 SUM[7][7] <= A[7];
end
//Assign B[n] to SUM
/*
assign SUM[i][0] = B[0];
assign SUM[i][1] = B[1];
assign SUM[i][2] = B[2];
assign SUM[i][3] = B[3];
assign SUM[i][4] = B[4];
assign SUM[i][5] = B[5];
assign SUM[i][6] = B[6];
assign SUM[i][7] = B[7];
*/
/*
generate
    for(i=0; i <= 7; i = i + 1) // first row (J=0)
    begin : first row
        full_adder fa_1(.A_i(SUM[i][0]),.B_i(B[0]),.C_i(1'b0),.S_o(SUM[i][0]),.C_o(CARRY[i][0]));
    end
endgenerate
*/
generate 

    for(i=0; i <= 7; i = i + 1) // first row (J=0)
    begin : first_row
        full_adder fa_1(.A_i(SUM[i][0]),.B_i(B[0]),.C_i(1'b0),.S_o(SUM[i][0]),.C_o(CARRY[i][0]));
    end

    for(j = 1; j <= 7; j = j + 1)
    begin : column
        for(i=0; i <= 7; i = i + 1) // other rows[]
        begin : row
            full_adder fa(.A_i(SUM[i+1][j-1]),.B_i(B[j]),.C_i(CARRY[i][j-1]),.S_o(SUM[i][j]),.C_o(CARRY[i][j]));
        end
    end
endgenerate

endmodule 


// Full Adder module 

module full_adder(A_i, B_i, C_i, C_o, S_o);

input  A_i, B_i, C_i;
output C_o, S_o;

wire  A_i, B_i, C_i;
wire C_o;
reg S_o;

//assign 
always@(*)
begin
S_o = (A_i ^ B_i ^ C_i);
end 
assign C_o = ((A_i & B_i) | (B_i & C_i) | (A_i & C_i)); 

endmodule

我在Quartus中收到此错误:&#34;错误(10663):csm.v(59)处的Verilog HDL端口连接错误:输出或输入端口&#34; S_o&#34;必须连接到结构网表达式&#34;

我只是没有看到错误。如果你们给我一个提示,我会很感激(我必须尽快完成这个代码:()。

谢谢大家。

2 个答案:

答案 0 :(得分:2)

S_o是一个分配SUM的输出,它是reg,这是非法的。即使它是合法的,所有SUM[i][0]上也有多个驱动程序,你可以反馈它。

full_adder fa_1(.A_i(SUM[i][0]),.B_i(B[0]),.C_i(1'b0),.S_o(SUM[i][0]),.C_o(CARRY[i][0]));

reg [8:0] SUM [8:0];更改为wire [8:0] SUM [8:0];并删除always块(或转换为assign语句)。然后修复你生成循环。您可能需要考虑绘制一个框图来可视化全加器的连接。

答案 1 :(得分:1)