Challenge - 5 Problems
Parameterized Module Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of parameterized module instantiation
What is the output of the following Verilog code when simulated?
Verilog
module adder #(parameter WIDTH = 4) (input [WIDTH-1:0] a, b, output [WIDTH-1:0] sum); assign sum = a + b; endmodule module test; wire [7:0] result; reg [7:0] x = 8'd15, y = 8'd10; adder #(.WIDTH(8)) my_adder(.a(x), .b(y), .sum(result)); initial begin #1 $display("Result = %d", result); end endmodule
Attempts:
2 left
💡 Hint
Check the parameter WIDTH and how it affects the input and output widths.
✗ Incorrect
The parameter WIDTH is set to 8, so inputs and output are 8 bits wide. Adding 15 and 10 results in 25, which fits in 8 bits.
❓ Predict Output
intermediateEffect of default parameter in module
What will be the output of this Verilog code snippet?
Verilog
module multiplier #(parameter FACTOR = 3) (input [3:0] in, output [7:0] out); assign out = in * FACTOR; endmodule module test; reg [3:0] val = 4'd4; wire [7:0] result; multiplier mul(.in(val), .out(result)); initial begin #1 $display("Result = %d", result); end endmodule
Attempts:
2 left
💡 Hint
Look at the default parameter FACTOR and the input value.
✗ Incorrect
The default FACTOR is 3, input is 4, so output is 4 * 3 = 12.
🔧 Debug
advancedIdentify the error in parameterized module instantiation
What error will this Verilog code produce when compiled?
Verilog
module shift #(parameter WIDTH = 4) (input [WIDTH-1:0] in, output [WIDTH-1:0] out); assign out = in << 1; endmodule module test; wire [3:0] result; reg [3:0] data = 4'b1010; shift #(.WIDTH(3)) sh(.in(data), .out(result)); endmodule
Attempts:
2 left
💡 Hint
Check the widths of input and output ports versus the parameter WIDTH.
✗ Incorrect
The parameter WIDTH is set to 3, but input 'data' is 4 bits wide. This causes a width mismatch error during instantiation.
📝 Syntax
advancedCorrect syntax for parameter override in module instantiation
Which option shows the correct way to override a parameter WIDTH to 16 during module instantiation?
Verilog
module counter #(parameter WIDTH = 8) (input clk, output reg [WIDTH-1:0] count); always @(posedge clk) count <= count + 1; endmodule module test; wire [15:0] cnt; reg clk = 0; // Instantiate counter here endmodule
Attempts:
2 left
💡 Hint
Remember the syntax for named parameter override uses .param_name(value).
✗ Incorrect
The correct syntax uses #(.WIDTH(16)) with parentheses, not equal signs or missing parentheses.
🚀 Application
expertDetermine the number of bits in output for nested parameterized modules
Given the following Verilog code, what is the width of the output wire 'final_out'?
Verilog
module stage #(parameter WIDTH = 4) (input [WIDTH-1:0] in, output [WIDTH-1:0] out); assign out = in + 1; endmodule module pipeline #(parameter STAGES = 3, WIDTH = 4) (input [WIDTH-1:0] in, output [WIDTH-1:0] out); wire [WIDTH-1:0] stage_outs [0:STAGES]; assign stage_outs[0] = in; genvar i; generate for (i = 0; i < STAGES; i = i + 1) begin : gen_stages stage #(.WIDTH(WIDTH)) s(.in(stage_outs[i]), .out(stage_outs[i+1])); end endgenerate assign out = stage_outs[STAGES]; endmodule module test; wire [7:0] final_out; reg [7:0] input_val = 8'd10; pipeline #(.STAGES(5), .WIDTH(8)) p(.in(input_val), .out(final_out)); endmodule
Attempts:
2 left
💡 Hint
Check how the WIDTH parameter is passed through the nested modules.
✗ Incorrect
The WIDTH parameter is set to 8 in the pipeline instantiation and passed to each stage. The output width remains 8 bits.
