Challenge - 5 Problems
Port Connection Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of module instantiation by position
What is the output of the following Verilog code when the module
test_module is instantiated by position?Verilog
module test_module(input wire a, input wire b, output wire y); assign y = a & b; endmodule module top; reg x1 = 1'b1; reg x2 = 1'b0; wire out; test_module inst(x1, x2, out); initial begin $display("Output: %b", out); end endmodule
Attempts:
2 left
💡 Hint
Remember that port connections by position match ports in the order they are declared in the module.
✗ Incorrect
The module
test_module has ports a, b, and y in that order. The instantiation connects x1 to a (1), x2 to b (0), so output y is 1 & 0 = 0.❓ Predict Output
intermediateOutput of module instantiation by name
What is the output of the following Verilog code when the module
test_module is instantiated by name?Verilog
module test_module(input wire a, input wire b, output wire y); assign y = a | b; endmodule module top; reg x1 = 1'b0; reg x2 = 1'b1; wire out; test_module inst(.b(x2), .a(x1), .y(out)); initial begin $display("Output: %b", out); end endmodule
Attempts:
2 left
💡 Hint
Port connections by name allow you to connect ports in any order.
✗ Incorrect
The module
test_module has ports a and b. The instantiation connects b to x2 (1) and a to x1 (0). The output y is a | b = 0 | 1 = 1.❓ Predict Output
advancedEffect of swapping port order in positional connection
Given the module
mod below, what is the output when instantiated with swapped inputs by position?Verilog
module mod(input wire a, input wire b, output wire y); assign y = a ^ b; endmodule module top; reg p = 1'b1; reg q = 1'b0; wire result; mod instance(q, p, result); initial begin $display("Result: %b", result); end endmodule
Attempts:
2 left
💡 Hint
Positional connections depend on the order of ports in the module declaration.
✗ Incorrect
The module expects
a then b. The instantiation passes q=0 as a and p=1 as b. XOR of 0 and 1 is 1.❓ Predict Output
advancedError when mixing positional and named port connections
What error occurs when mixing positional and named port connections in this instantiation?
Verilog
module example(input wire a, input wire b, output wire y); assign y = a & b; endmodule module top; reg x = 1'b1; reg z = 1'b0; wire out; example inst(.b(z), x, .y(out)); initial begin $display("Out: %b", out); end endmodule
Attempts:
2 left
💡 Hint
In Verilog, positional port connections must come before any named connections.
✗ Incorrect
Verilog requires that all positional port connections precede any named port connections in a module instantiation. In this example, the instantiation starts with a named connection `.b(z)`, followed by a positional connection `x`, which violates this rule and results in a syntax error.
🧠 Conceptual
expertWhy prefer named port connections in large modules?
Which reason best explains why named port connections are preferred over positional connections in large Verilog modules?
Attempts:
2 left
💡 Hint
Think about how easy it is to make mistakes when connecting many ports.
✗ Incorrect
Named port connections explicitly specify which signal connects to which port, reducing errors from incorrect ordering. Positional connections rely on order, which can cause bugs in large modules.
