本文为 Verilog 学习总结,讲解 Verilog 语法的基本概念。
Verilog 模块的基本概念
首先来看一个二选一 MUX 程序,支持了逻辑行为的描述:
module muxtow(out, a, b, sl);
input a,b,sl;
output out;
reg out;
always@(sl or a or b) // 只要sl或a或b一个变化,就执行下面的语句
if(!sl) out = a;
else out =b;
endmodule
带有与非门的二选一 MUX 程序(逻辑表达式):
module muxtwo(out, a, b, sl);
input a,b,sl;
output out;
wire nsl,sela,selb; // 定义内部连接线
assign nsl=~sl;
assign sela=a&nsl; // 按位与运算
assign selb=b&sl;
assign out=sela|selb;
endmodule
另一种写法(支持基于逻辑单元互联结构的描述):
module muxtwo(out, a, b, sl);
input a,b,sl;
output out;
not ul(nsl,sl);
and #1 u2(sela,a,nsl); // #1表示延时一个单位时间
and #1 u3(selb,b,sl);
or #1 u4(out,sela,selb);
endmodule