Mechanic2Tinzo

导航

2024.07.02

Verilog语法的基本概念

Verilog HDL描述的电路设计就是模块。行为&结构描述。

一. Verilog模块的基本概念

//二选一多路选择器
/*单行注释*/
//
注释 module muxtwo (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
//带与非门的二选一多路选择器
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&nsl;
          assign out=sela|selb;       //按位或运算
endmodule
//多路选择器
module muxtwo (out, a, b, sl);
input a,b,sl;
output out;
        not            u1(nsl,sl);
        and    #1   u2(sela,a,nsl);
        and    #1   u2(sela,a,nsl);
        or     #1   u2(out,sela,selb);
endmodule

 

posted on 2024-07-02 11:27  Tinzo_Zhang  阅读(26)  评论(0)    收藏  举报