modules

By now, you're familiar with a , which is a circuit that interacts with its outside through input and output ports. Larger, more complex circuits are built by composing bigger modules out of smaller modules and other pieces (such as assign statements and always blocks) connected together. This forms a hierarchy, as modules can contain instances of other modules. module

The figure below shows a very simple circuit with a sub-module. In this exercise, create one instance of module , then connect the module's three pins (, , and ) to your top-level module's three ports (wires , , and ). The module is provided for you — you must instantiate it. mod_ain1in2outaboutmod_a

When connecting modules, only the ports on the module are important. You do not need to know the code inside the module. The code for module looks like this: mod_a
1 module top_module ( input a, input b, output out );
2  mod_a instance1(
3     .out(out),
4     .in1(a), 
5     .in2(b)
6     );
7 endmodule

此题考察了命名,参考题目中的提示

1 By name
2 Connecting signals to a module's ports by name allows wires to remain correctly connected even if the port list changes. This syntax is more verbose, however.
3 
4 mod_a instance2 ( .out(wc), .in1(wa), .in2(wb) );
5 
6 The above line instantiates a module of type named "instance2", then connects signal (outside the module) to the port named , to the port named , and to the port named . Notice how the ordering of ports is irrelevant here because the connection will be made to the correct name, regardless of its position in the sub-module's port list. Also notice the period immediately preceding the port name in this syntax. mod_awain1wbin2wcout

 而此处的mod_a instance1只作为一个命名,是可以任取名字的,可以对instance进行改变,例如网上也有如此写法:mod_a mod_a_inst(.in1(a),.in2(b),.out(out));

自然也是可以的

posted @ 2023-04-19 09:49  江左子固  阅读(24)  评论(0)    收藏  举报