1 输出高低电平
module top_module(
output zero
);// Module body starts after semicolon
assign zero=1'b0;
endmodule
module top_module(
output zero
);// Module body starts after semicolon
assign zero=1'b1;
endmodule
2 Wire
Verilog 中重要的一种信号类型,我们将通过建立一个模块 (module) 来实现 wire。所谓模块就是前两题中我们构建的东西,拥有输入输出端口的黑盒,在之后我们会详细讲解模块,wire 的中文可以翻译为导线,但 Verilog 中的 wire 和现实中的导线不同,wire 应该理解为一个信号,信号是有方向性的,wire 从 A 点输出,输入到 B 点和 C 点。wire 一般只有一个 source,即从某一点输出,但可以有多个 sinks,即输入到多个点。A 点通常会被称为一个驱动(driver),把某个值驱动到 wire 上。
module top_module( input in, output out );
assign out=in;
endmodule
3 Wire4
当你使用多条 assign 语句时,他们之间的顺序是无关紧要的,这点同顺序执行的软件代码不同。事实上,大部分 Verilog 代码之间的顺序都不会对结果产生影响。assign 描述的是端口之间的连接关系,而不是一次复制右值,赋给左值的复制黏贴,连接关系不存在先后之分。
这里要澄清一个容易混淆的概念,图中的绿线代表的是 wire 之间的连接,而不是 wire 本身。即 wire 是连线两端的信号,而不是连线本身。上图中的模块实际声明了 7 个 wire 信号(a, b, c, w, x, y, z)。这是因为模块的输入输出端口实际上都是 wire。
module top_module(
input a,b,c,
output w,x,y,z );
assign w=a;
assign x=b;
assign y=b;
assign z=c;
endmodule
4 非门
module top_module( input in, output out );
assign out=~in;
endmodule
5 AND门
module top_module(
input a,
input b,
output out );
assign out=a&b;
endmodule
6 或非门
module top_module(
input a,
input b,
output out );
assign out=~(a|b);
endmodule
7 Xnorgate
同或门 (XNor Gate) 是异或门 (Nor Gate) 的取反输出。异或门的输入输出可以概括为:(输入)相同(输出)为 0 ,不同为 1 。
取反(),与(&),或(|),异或(^),同或(^)
module top_module(
input a,
input b,
output out );
assign out=~(a^b);
endmodule
8
Wire decl - HDLBits (01xz.net)
module top_module(
input a,
input b,
input c,
input d,
output out,
output out_n );
wire one= a&b;
wire two= c&d;
wire three= one|two;
assign out = three;
assign out_n = ~three;
endmodule
97458 - HDLBits (01xz.net)
module top_module (
input p1a, p1b, p1c, p1d, p1e, p1f,
output p1y,
input p2a, p2b, p2c, p2d,
output p2y );
assign p1y=(p1a&p1c&p1b)|(p1f&p1e&p1d);
assign p2y=(p2a&p2b)|(p2c&p2d);
endmodule