案例练习:
1、创建一个实现非门
的模块
Verilog 有单独的按位非 ( ~) 和逻辑非 ( !) 运算符。
module top_module( input in, output out );
//assign out = !in; // 逻辑非
assign out = ~in`b1; // 按位非
endmodule
2、创建一个实现AND与门
的模块
该电路现在有三根导线(a、b和out)。电线a和b已经有输入端口驱动到它们的值。但是电线out目前不是由任何东西驱动的。编写一个用信号和的 ANDassign驱动的语句。
Verilog 有单独的位与 ( &) 和逻辑与 ( &&) 运算符
module top_module(
input a,
input b,
output out );
assign out = a && b;
endmodule
3、创建一个实现NOR或非门
的模块
创建一个实现 NOR 门的模块。或非门是一个输出反相的或门。
用 Verilog 编写的 NOR 函数需要两个运算符。
Verilog 有单独的按位或 ( |) 和逻辑或 ( ||) 运算符
module top_module(
input a,
input b,
output out );
assign out = !(a || b);
endmodule
4、创建一个实现XNOR异或非门
的模块
按位异或运算符是^
module top_module(
input a,
input b,
output out );
assign out = !(a^b);
endmodule