
8位非门
`timescale 1ns/10psmodule device(A,Y);
input [7:0]A;
output [7:0]Y;
assign Y=~A;
endmodulemodule device_tb;
reg a;
wire y;device device(.A(a),.Y(y));initial begina<=8'h01; #10 a<=8'h02; #10 a<=8'h03; #10 a<=8'h05; #10 a<=8'h09; #10 a<=8'h0a; #10 a<=8'h0f; #10 a<=8'h04; #10 $stop;end
endmodule
与非门
`timescale 1ns/10psmodule and_not(A,B,Y);
input A;
input B;
output Y;
assign y=~(A&B);
endmodulemodule and_not_tb;
reg aa; //输入的变量都定义成reg
reg bb;
wire yy;//输出的变量定义为wire
and not and_not(.A(aa),.B(bb).Y(yy));
initial beginaa<=0; bb<=0; //reg变量赋值的时候要使用带箭头的等号#10 aa<=0; bb<=1;#10 aa<=1; bb<=0;#10 aa<=1; bb<=1; #10 $stop;
end
endmodule
四位与非门
`timescale 1ns/10psmodule and_not_4(A,B,Y);
input [3:0] A;
input [3:0] B;
output [3:0] Y;
assign y=~(A&B);
endmodulemodule and_not_4_tb;
reg [3:0] aa; //输入的变量都定义成reg
reg [3:0] bb;
wire [3:0] yy;//输出的变量定义为wire
and_not_4 and_not_4(.A(aa),.B(bb).Y(yy));
initial beginaa<=4'b0000; bb<=4'b0000; //reg变量赋值的时候要使用带箭头的等号#10 aa<=4'b0100; bb<=4'b0110;#10 aa<=4'b1110; bb<=4'b0001;#10 aa<=4'b0110; bb<=4'b0000; //注意多位的时候需要用‘#10 $stop;
end
endmodule
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!