3

I want to have parameterized module. It has the following definition:

module example (...);
    parameter A = 2;
    parameter B = 2;
    parameter C = A + B;

endmodule

However, when I print out the parameter values, I get A = 2, B = 2, and C = 1... Any ideas why?

1 Answer 1

6

Found a solution - use localparam.

module example (...);
  parameter A = 2;
  parameter B = 2;
  localparam C = A + B;

endmodule
Sign up to request clarification or add additional context in comments.

2 Comments

In fact in your original question, C should be equal to 4. However, it is dangerous and very possible to be overrided because C is a parameter. Using localparam is the right way to define a parameter which cannot be override by defparam or instance parameter value assignments.
Except localparams can not be used for port lists, using verilog-2001 style port declarations.

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.