In Verilog, you can declare wires/registers
- as ports and connect them at instantiation (
port_Ain example) - as ports and connect them "later"/"outside" using hierarchical names (
port_Bin example) - private and still connect them using hierarchical names (
internal_in example)
Example:
module SubModule (
input wire in_port_A,
output wire out_port_A,
input wire in_port_B,
output wire out_port_B
);
wire internal_wire;
reg internal_reg = 0;
assign out_port_A = in_port_A;
assign out_port_B = in_port_B;
endmodule
module Test;
reg A = 0;
wire a;
reg B = 0;
wire b;
reg I = 0;
wire i;
wire r;
SubModule sub(
.in_port_A(A),
.out_port_A(a)
);
assign sub.in_port_B = B;
assign b = sub.out_port_B;
assign sub.internal_wire = I;
assign i = sub.internal_wire;
assign r = sub.internal_reg;
initial begin
$display ("a: %0b", a);
A = 1;
$display ("a: %0b", a);
$display ("b: %0b", b);
B = 1;
$display ("b: %0b", b);
$display ("i: %0b", i);
I = 1;
$display ("i: %0b", i);
$display ("r: %0b", r);
sub.internal_reg = 1;
$display ("r: %0b", r);
end
endmodule
Output:
a: 0
a: 1
b: 0
b: 1
i: 0
i: 1
r: 0
r: 1
What are the differences between these methods? Is declaring them as ports merely to convey the intention of "this should be used/connected outside"?