Port connections link signals between modules. Connecting by name or by position helps organize and control these links clearly.
Port connection by name vs by position in Verilog
module_name instance_name (port1, port2, port3);
// or by name
module_name instance_name (.port1(signal1), .port2(signal2), .port3(signal3));By position: ports are connected in the order they are declared in the module.
By name: ports are connected explicitly by their names, order does not matter.
my_module inst1 (a, b, c);
my_module inst2 (.port1(a), .port2(b), .port3(c));
my_module inst3 (.port3(c), .port1(a), .port2(b));
This example shows a simple module with two inputs and one output. It is instantiated twice: once connecting ports by position, once by name. Both produce the same output.
module my_module(input wire in1, input wire in2, output wire out); assign out = in1 & in2; endmodule module top; wire a = 1'b1; wire b = 1'b0; wire c_pos, c_name; // Connect by position my_module inst_pos (a, b, c_pos); // Connect by name my_module inst_name (.in2(b), .out(c_name), .in1(a)); initial begin $display("Output by position: %b", c_pos); $display("Output by name: %b", c_name); end endmodule
Connecting by name is safer when module ports change order or new ports are added.
Connecting by position is shorter but can cause errors if port order is forgotten.
Use named connections for better readability and maintenance in bigger designs.
Port connection by position links signals in the order ports are declared.
Port connection by name links signals explicitly by port names, order does not matter.
Named connections improve clarity and reduce errors in complex modules.
Practice
Solution
Step 1: Understand port connection by position
Port connection by position links signals to ports based on the order the ports are declared in the module.Step 2: Understand port connection by name
Port connection by name links signals explicitly by specifying the port names, so order does not matter.Final Answer:
By name connects ports explicitly by their names; by position connects ports in the order declared. -> Option DQuick Check:
Port connection by name = explicit naming [OK]
- Confusing order with explicit naming
- Thinking by position allows skipping ports
- Assuming by name requires fewer ports
Solution
Step 1: Recall named port connection syntax
Named connections use dot notation: .port_name(signal_name).Step 2: Match syntax options
module_name (.port1(input_signal), .port2(output_signal)); matches the correct syntax: module_name (.port1(input_signal), .port2(output_signal));Final Answer:
module_name (.port1(input_signal), .port2(output_signal)); -> Option BQuick Check:
Named ports use dot and parentheses [OK]
- Using commas without dots for named ports
- Using braces or arrows which are invalid
- Confusing named and positional syntax
module my_module(input a, input b, output c);
Which instantiation will correctly connect signals
x, y, and z by position?Solution
Step 1: Understand port order in module
The ports are declared in order: a, b, c.Step 2: Match signals by position
By position, the first signal connects to 'a', second to 'b', third to 'c'. So (x, y, z) matches correctly.Final Answer:
my_module instance1 (x, y, z); -> Option CQuick Check:
Position order = a=x, b=y, c=z [OK]
- Swapping signal order in positional connection
- Using named syntax but calling it positional
- Connecting signals in wrong order
my_module instance1 (x, .b(y), z);
Assuming
my_module ports are a, b, c in order.Solution
Step 1: Check connection styles used
The instantiation mixes positional (x, z) and named (.b(y)) connections.Step 2: Recall Verilog rules on mixing connections
Verilog does not allow mixing positional and named port connections in the same instantiation.Final Answer:
Mixing positional and named connections is not allowed. -> Option AQuick Check:
Mixing connection styles = error [OK]
- Thinking mixed connections are allowed
- Ignoring order importance in positional connections
- Assuming named connections can appear anywhere
(input clk, input reset, output reg done). You want to instantiate it with signals clk_sig, rst_sig, and done_sig. Which instantiation style is safer and why?Solution
Step 1: Consider risks of positional connection
Positional connection depends on port order; if order changes, connections break.Step 2: Consider benefits of named connection
Named connection explicitly links signals to port names, so order changes do not cause errors.Final Answer:
By name, because it explicitly connects signals to ports regardless of order. -> Option AQuick Check:
Named connection = safer for clarity [OK]
- Assuming positional is always simpler and safer
- Thinking named connection matches by data type
- Believing positional allows skipping ports
Ready to prove it?
Pass the test and this pattern moves unknown
