Verilog HDL语言编写与门、与非门、或门、或非门、同或、异或、缓冲器、非门。

1、代码

module Gate(S_in1,S_in2,Out_and,Out_nand,Out_or,Out_nor,Out_xnor,Out_xor,Out_buf,Out_not);

input S_in1;
input S_in2;
output Out_and,Out_nand,Out_or,Out_nor,Out_xnor,Out_xor,Out_buf,Out_not;

 

and(Out_and,S_in1,S_in2); //与门
nand(Out_nand,S_in1,S_in2); //与非门
or(Out_or,S_in1,S_in2);//或门
nor(Out_nor,S_in1,S_in2);//或非门
xnor(Out_xnor,S_in1,S_in2);//同或
xor(Out_xor,S_in1,S_in2);//异或门
buf(Out_buf,S_in1);//缓冲器
not(Out_not,S_in1);//非门
//nand na1 3inp(Out_nand,S_in1,S_in2,S_in3)//三个输入

 

endmodule 

2、testbench

`timescale 1ns/1ns

module Gate_tb;
reg S_in1;
reg S_in2;
wire Out_and;
wire Out_nand;
wire Out_or;
wire Out_nor;
wire Out_xnor;
wire Out_xor;
wire Out_buf;
wire Out_not;

 

Gate u0(
    .S_in1(S_in1),
    .S_in2(S_in2),
    .Out_and(Out_and),
    .Out_nand(Out_nand),
    .Out_or(Out_or),
    .Out_nor(Out_nor),
    .Out_xnor(Out_xnor),
    .Out_xor(Out_xor),
    .Out_buf(Out_buf),
    .Out_not(Out_not)
);
initial begin
S_in1=0;S_in2=0;
#100;
S_in1=0;S_in2=1;
#100;
S_in1=1;S_in2=0;
#100;
S_in1=1;S_in2=1;
#100;
end
endmodule 

 

  • 17
    点赞
  • 80
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值