0

I have a code where I am using recursion,

module mult(a,b,c)
  generate
    always @(*) begin
     /* a few calculations */
     if(x < 10)
       flag = 1;
     else
       flag = 0; 
    end
     if( flag == 1)
        mult(x,y,z);
     else
        z = x*y;
  endgenerate
endmodule

However, this code returns an error saying that flag is not a constant. I understand that one cannot use an if-else outside the always block, by using registers or wires or integers. However, is there any other way I can implement the code?

Recursion seems to work only in a generate block but outside the always block.

0

1 Answer 1

1

Conditionals in generate blocks need to be constant at elaboration time. Typically they either `defines or parameters of the module.

You don't declare 'x' at all in your example... In fact there are numerous errors that would prevent this from compiling. Enough that it's hard to figure our your intent. Can you provide a bit of detail on this?

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.