Verilog生成语句问题

时间:2014-03-27 18:23:17

标签: verilog

嘿我试图在verilog中使用生成函数,代码编译成功但无法模拟。

我收到了以下错误:

Illegal output or inout port connection for "port 'sum'".
Illegal output or inout port connection for "port 'carry'".

有谁能告诉我我做错了什么。感谢

module test(input wire [2:0] a, 
        input wire [2:0] b,
        output reg [2:0] s,
        output reg [2:0] c);

genvar i;
generate 
for(i=0;i<3;i=i+1)
    adder_half inst(.sum(s[i]),.carry(c[i]),.a(a[i]),.b(b[i]));
endgenerate 

endmodule

module adder_half(
  output sum,carry,
  input a,b
    );
 xor(sum,a,b);
 and(carry,a,b);

endmodule

1 个答案:

答案 0 :(得分:3)

reg类型仅用于过程分配,但实例连接更像是连续分配。

从输出中删除reg关键字。变化:

    output reg [2:0] s,
    output reg [2:0] c);

为:

    output [2:0] s,
    output [2:0] c);