What is the purpose of the parameter keyword in Verilog modules?
The parameter keyword allows you to define constants inside a module that can be changed when the module is instantiated. This makes the module flexible and reusable with different settings.
Click to reveal answer
beginner
How do you override a parameter value when instantiating a Verilog module?
You override a parameter by specifying the new value inside #() after the module name during instantiation. For example: my_module #(.WIDTH(8)) instance_name (...);
Click to reveal answer
beginner
Example: What does this parameterized module do?
module adder #(parameter WIDTH = 4) (input [WIDTH-1:0] a, b, output [WIDTH-1:0] sum); assign sum = a + b; endmodule
This module adds two numbers a and b of size WIDTH bits. The WIDTH parameter sets the bit-width and defaults to 4 if not changed.
Click to reveal answer
beginner
Why are parameterized modules useful in hardware design?
They let you create one module that can work with different data sizes or configurations without rewriting code. This saves time and reduces errors.
Click to reveal answer
beginner
Can parameters be changed inside the module after compilation?
No, parameters are constants during simulation and synthesis. They must be set at instantiation and cannot be changed dynamically inside the module.
Click to reveal answer
What keyword is used to define a constant value inside a Verilog module that can be changed at instantiation?
Areg
Bparameter
Cwire
Dinput
✗ Incorrect
The parameter keyword defines constants that can be overridden when the module is instantiated.
How do you override a parameter named WIDTH to 8 when instantiating a module named adder?
Aadder #(.WIDTH(8)) instance_name (...);
Badder #(8) instance_name (...);
Cadder #(WIDTH=8) instance_name (...);
Dadder instance_name #(WIDTH=8) (...);
✗ Incorrect
The correct syntax uses named parameter override: module_name #(.PARAMETER(value)) instance (...);
If a parameter is not overridden during instantiation, what value does it have?
AThe default value set in the module
BZero
CUndefined
DRandom
✗ Incorrect
Parameters use their default values defined inside the module if not overridden.
Can parameters be changed inside the module after synthesis?
AOnly during simulation
BYes, anytime
CNo, they are fixed constants
DOnly if declared as reg
✗ Incorrect
Parameters are constants fixed at compile time and cannot be changed dynamically.
What is a main benefit of using parameterized modules?
AFaster simulation
BDynamic runtime changes
CAutomatic debugging
DReusability with different configurations
✗ Incorrect
Parameterized modules allow reusing the same code with different settings, improving flexibility.
Explain how the parameter keyword works in Verilog modules and how you can change parameter values when using the module.
Think about how to make a module flexible for different bit widths.
You got /4 concepts.
Describe a real-life example where parameterized modules would be helpful in hardware design.
Imagine designing a calculator that can add numbers of different sizes.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using the parameter keyword in a Verilog module?
easy
A. To specify the clock frequency inside the module
B. To define constants that can be changed when the module is instantiated
C. To declare input and output ports of the module
D. To create variables that change during simulation
Solution
Step 1: Understand the role of parameter
The parameter keyword defines constants inside a module that can be set when the module is created.
Step 2: Compare with other options
Input/output ports are declared with input and output, not parameter. Clock frequency is not set by parameter alone. Variables that change during simulation are declared differently.
Final Answer:
To define constants that can be changed when the module is instantiated -> Option B
Quick Check:
Parameter = adjustable constant [OK]
Hint: Parameters are like adjustable settings for modules [OK]
Common Mistakes:
Confusing parameters with input/output ports
Thinking parameters change during simulation
Assuming parameters set clock frequency directly
2. Which of the following is the correct syntax to declare a parameter named WIDTH with a default value of 8 inside a Verilog module?
easy
A. define WIDTH = 8;
B. param WIDTH = 8;
C. parameter WIDTH : 8;
D. parameter WIDTH = 8;
Solution
Step 1: Recall Verilog parameter syntax
The correct way to declare a parameter is using the keyword parameter followed by the name, an equals sign, and the value, ending with a semicolon.
Step 2: Check each option
parameter WIDTH = 8; matches the correct syntax. param WIDTH = 8; uses incorrect keyword param. parameter WIDTH : 8; uses colon instead of equals. define WIDTH = 8; uses define which is for macros, not parameters.
Final Answer:
parameter WIDTH = 8; -> Option D
Quick Check:
Parameter syntax = keyword + name + = + value [OK]
Hint: Remember: parameter name = value; [OK]
Common Mistakes:
Using 'param' instead of 'parameter'
Using colon ':' instead of equals '='
Confusing parameters with macros (#define)
3. Given the following module and instantiation, what is the width of the output out?
Step 1: Identify parameter override in instantiation
The module has a default parameter WIDTH=4, but the instantiation overrides it with WIDTH=6.
Step 2: Determine output width from parameter
The output width is defined as [WIDTH-1:0], so with WIDTH=6, output is 6 bits wide.
Final Answer:
6 bits -> Option C
Quick Check:
Parameter override sets WIDTH=6 [OK]
Hint: Check parameter override in #(...) during instantiation [OK]
Common Mistakes:
Ignoring parameter override and using default
Assuming output width is always 1 bit
Confusing input width with output width
4. Identify the error in the following Verilog code snippet:
module adder #(parameter WIDTH = 8) (input [WIDTH-1:0] a, b, output [WIDTH-1:0] sum);
assign sum = a + b;
endmodule
adder #(WIDTH=16) my_adder (.a(a_signal), .b(b_signal), .sum(sum_signal));
medium
A. Parameter override syntax is incorrect in instantiation
B. Missing semicolon after module declaration
C. Input and output port widths are not declared properly
D. Addition operation is invalid for vectors
Solution
Step 1: Check parameter override syntax
The correct syntax for parameter override uses dot notation with parentheses: #(.WIDTH(16)), not #(WIDTH=16).
Step 2: Verify other parts
Semicolons and port widths are correct. Addition on vectors is valid in Verilog.
Final Answer:
Parameter override syntax is incorrect in instantiation -> Option A
Quick Check:
Use #(.PARAM(value)) for parameter override [OK]
Hint: Use #(.PARAM(value)) syntax for parameters [OK]
Common Mistakes:
Using = instead of ( ) in parameter override
Forgetting dot before parameter name
Assuming addition on vectors is invalid
5. You want to create a parameterized Verilog module shift_reg that shifts input bits by a configurable amount SHIFT. Which of the following module declarations correctly uses the parameter keyword and allows setting SHIFT during instantiation?
hard
A. module shift_reg #(parameter SHIFT = 2) (input [7:0] in, output [7:0] out); assign out = in << SHIFT; endmodule
B. module shift_reg (parameter SHIFT = 2) (input [7:0] in, output [7:0] out); assign out = in << SHIFT; endmodule
C. module shift_reg #(param SHIFT = 2) (input [7:0] in, output [7:0] out); assign out = in << SHIFT; endmodule
D. module shift_reg #(parameter SHIFT : 2) (input [7:0] in, output [7:0] out); assign out = in << SHIFT; endmodule
Solution
Step 1: Check parameter declaration syntax
module shift_reg #(parameter SHIFT = 2) (input [7:0] in, output [7:0] out); assign out = in << SHIFT; endmodule correctly declares parameter SHIFT = 2 inside #(...) after module name, which is the standard syntax.
Step 2: Validate other options
module shift_reg (parameter SHIFT = 2) (input [7:0] in, output [7:0] out); assign out = in << SHIFT; endmodule incorrectly places parameter inside port list. module shift_reg #(param SHIFT = 2) (input [7:0] in, output [7:0] out); assign out = in << SHIFT; endmodule uses invalid keyword param. module shift_reg #(parameter SHIFT : 2) (input [7:0] in, output [7:0] out); assign out = in << SHIFT; endmodule uses colon instead of equals.
Final Answer:
module shift_reg #(parameter SHIFT = 2) (input [7:0] in, output [7:0] out); assign out = in << SHIFT; endmodule -> Option A
Quick Check:
Parameter with default value inside #(parameter ...) [OK]
Hint: Declare parameters inside #(parameter NAME = value) [OK]
Common Mistakes:
Placing parameter inside port list
Using 'param' instead of 'parameter'
Using colon ':' instead of equals '='
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.