0

I was trying to use the generate function in Verilog. The code compiled successfully, but it couldn't simulate. I get the following errors:

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

Could anyone tell me what am I doing wrong?

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
4
  • I didn't made one, I directly used the tool's( ModelSim) simulate option. Commented Mar 27, 2014 at 18:42
  • I changed my adder output type to reg, still I'm getting the same error. module adder_half( output reg sum,carry, input a,b ); always@(*) begin sum=a^b; carry=a&b; end endmodule Commented Mar 27, 2014 at 18:52
  • Sorry my fault, and thanks it started working, but am i not supposed to use reg type inside blocks (here its generate block) Commented Mar 27, 2014 at 19:00
  • The type is only relevant for current module. an output of reg is connected to wire at the next level of hierarchy. Commented Mar 27, 2014 at 20:10

1 Answer 1

3

The reg type is only used for procedural assignments, but instance connections are treated more like continuous assignments.

Remove the reg keyword from your outputs. Change:

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

to:

    output [2:0] s,
    output [2:0] c);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.