1、Wire
module top_module (
input in,
output out);
assign out = in;endmodule
2、GND
module top_module (
output out);
assign out = 1'b0;
endmodule
3、NOR
module top_module (
input in1,
input in2,
output out);
assign out = ~(in1|in2);
endmodule
4、another gare
module top_module (
input in1,
input in2,
output out);
assign out = in1&(~in2);
endmodule
5、Two gates
module top_module (
input in1,
input in2,
input in3,
output out);
assign out = (~(in1^in2))^in3;
endmodule
6、More logic gates
module top_module(
input a, b,
output out_and,
output out_or,
output out_xor,
output out_nand,
output out_nor,
output out_xnor,
output out_anotb
);
assign out_and = a&b;
assign out_or = a|b;
assign out_xor = a^b;
assign out_nand = ~(a&b);
assign out_nor = ~(a|b);
assign out_xnor = ~(a^b);
assign out_anotb = a&(~b);
endmodule
7、7420 chips
module top_module (
input p1a, p1b, p1c, p1d,
output p1y,
input p2a, p2b, p2c, p2d,
output p2y );
assign p1y = ~(p1a&p1b&p1c&p1d);
assign p2y = ~(p2a&p2b&p2c&p2d);
endmodule
8、Truthtable1
计算出最小的运算方式然后直接写就可以了,具体运算方法叫卡诺图
module top_module(
input logic x3,
input logic x2,
input logic x1, // three inputs
output logic f // one output
);
assign f = x3 & x1 | x2 & x1 | ~x3 & x2;
endmodule
9、Two-bit equality
创建一个有两个2位输入 A [1:0]和 B [1:0]的电路,并产生一个输出 z。
如果 A = B,则 z 的值应为1,否则 z 应为0。
module top_module ( input [1:0] A, input [1:0] B, output z );
assign z = A==B?1'b1:1'b0;
endmodule
10、Simple circuit A
模块 A 应该实现函数 z = (x ^ y) & x。
module top_module (input x, input y, output z);
assign z = (x^y)&x;
endmodule
11、Simple circuit B
module top_module ( input x, input y, output z );
assign z = x==y?1'b1:1'b0;
endmodule
12、Combine circuits A and B
有关此处使用的子模块,请参见 10 和 11。顶层设计由两个子电路 A 和 B 的实例组成,如下所示。
module top_module (input x, input y, output z);
assign z = (((x ^ y) & x) | (x ~^ y)) ^ (((x ^ y) & x) & (x ~^ y));
endmodule