0
0
VerilogComparisonBeginner · 4 min read

Named vs Positional Port Mapping in Verilog: Key Differences and Usage

In Verilog, positional port mapping connects module ports by their order, while named port mapping connects ports explicitly by name. Named mapping is clearer and less error-prone, especially when modules have many ports or optional connections.
⚖️

Quick Comparison

This table summarizes the main differences between named and positional port mapping in Verilog.

FactorPositional Port MappingNamed Port Mapping
Connection MethodPorts connected by order of declarationPorts connected by explicit port names
ReadabilityLess readable for many portsMore readable and self-explanatory
Error RiskHigh risk if port order changesLow risk, order does not matter
Optional PortsDifficult to skip portsEasy to skip or reorder ports
MaintenanceHarder to maintain with changesEasier to maintain and update
UsageSimple or small modulesComplex or large modules
⚖️

Key Differences

Positional port mapping connects module ports strictly by their position in the module declaration. This means the first port in the instance connects to the first port in the module, the second to the second, and so on. If the order changes in the module or instance, the connections can break silently, causing bugs.

In contrast, named port mapping connects ports by explicitly specifying the port name and the signal it connects to. This makes the code easier to read and understand because each connection is labeled. It also allows skipping ports or changing the order without affecting functionality.

Named mapping is especially useful for modules with many ports or optional signals. It reduces errors and improves code clarity, making maintenance simpler. Positional mapping is shorter but less flexible and more error-prone.

⚖️

Code Comparison

Here is an example of positional port mapping for a simple module instantiation.

verilog
module adder(input wire a, input wire b, output wire sum);
  assign sum = a + b;
endmodule

module top;
  wire x = 1'b1;
  wire y = 1'b0;
  wire z;

  // Positional port mapping
  adder add1(x, y, z);
endmodule
↔️

Named Port Mapping Equivalent

The same module instantiated using named port mapping looks like this:

verilog
module adder(input wire a, input wire b, output wire sum);
  assign sum = a + b;
endmodule

module top;
  wire x = 1'b1;
  wire y = 1'b0;
  wire z;

  // Named port mapping
  adder add1(.a(x), .b(y), .sum(z));
endmodule
🎯

When to Use Which

Choose positional port mapping when working with very simple modules with few ports and when you want concise code. It is quick but can lead to errors if port order changes.

Choose named port mapping for modules with many ports, optional signals, or when clarity and maintainability are priorities. It prevents mistakes and makes your code easier to understand and update.

Key Takeaways

Named port mapping connects ports by name, making code clearer and safer.
Positional port mapping connects ports by order, which is shorter but error-prone.
Use named mapping for complex modules or when ports may change order.
Positional mapping suits simple modules with few ports for quick instantiation.
Named mapping improves maintainability and reduces bugs in large designs.