Verilog学习笔记之HDLBITS
Three modules
题目是:在顶层模块中例化3个模块
module top_module (
input clk,
input d,
output q
);
wire a, b; // Create two wires. I called them a and b.
// Create three instances of my_dff, with three different instance names (d1, d2, and d3).
// Connect ports by position: ( input clk, input d, output q)
my_dff d1 ( clk, d, a );
my_dff d2 ( clk, a, b );
my_dff d3 ( clk, b, q );
endmodule
这种实例化方法,在名称后面的括号里面全都是连接的信号,而没有端口名称。端口默认按顺序
Module add
module top_module(
input [31:0] a,
input [31:0] b,
output [31:0] sum
);
wire [15:0] low16,high16;
wire cout1,cout2;
add16 add16_1 (a[15:0],b[15:0],1'b0,low16,cout1);
add16 add16_2 (a[31:16],b[31:16],cout1,high16,cout2);
assign sum = {high16,low16};
endmodule
module add1 ( input a, input b, input cin, output sum, output cout );
assign {cout,sum} = a + b + cin;
// Full adder module here
endmodul
总结
首先是例化的括号里面,可以在信号后面加[]里面代表位数,并且没有的信号可以直接写1’b0;