hdlbits-Declaring-wires

Declaring wires

The circuits so far have been simple enough that the outputs are simple functions of the inputs. As circuits become more complex, you will need wires to connect internal components together. When you need to use a wire, you should declare it in the body of the module, somewhere before it is first used. (In the future, you will encounter more types of signals and variables that are also declared the same way, but for now, we'll start with a signal of type wire).

Wiredecl1

example

1
2
3
4
5
6
7
8
9
10
11
12
module top_module (
input in, // Declare an input wire named "in"
output out // Declare an output wire named "out"
);

wire not_in; // Declare a wire named "not_in"

assign out = ~not_in; // Assign a value to out (create a NOT gate).
assign not_in = ~in; // Assign a value to not_in (create another NOT gate).

endmodule // End of module "top_module"

Practice

Implement the following circuit. Create two intermediate wires (named anything you want) to connect the AND and OR gates together. Note that the wire that feeds the NOT gate is really wire out, so you do not necessarily need to declare a third wire here. Notice how wires are driven by exactly one source (output of a gate), but can feed multiple inputs.

If you're following the circuit structure in the diagram, you should end up with four assign statements, as there are four signals that need a value assigned.

Wiredecl2

solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
`default_nettype none
module top_module(
input a,
input b,
input c,
input d,
output out,
output out_n );

wire p;
assign p = a&b | c&d;

assign out = p;
assign out_n = ~p;

endmodule


hdlbits-Declaring-wires
http://456-xiao.github.io/2024/08/03/hdlbits-Declaring-wires/
作者
xyh
发布于
2024年8月3日
许可协议