半加器: 使用门: module ADD_half ( output c_out, sum, input a,b ); xor (sum,a,b); and (c_out,a,b); endmodule 使用抽象语句: module ADD_half_nogate ( output cout,sum, input a,b,cin); assign sum=a^b; assign cout=a&&b; endmodule 使用门定义去编写逻辑电路过于麻烦,以下都电路只会使用逻辑符号来描述。 全加器: module ADD_full ( output c_out,sum, input a,b,cin); wire w1, w2, w3; ADD_half_nogate M1 (w2,w1,a,b); ADD_half_nogate M2 (w3,sum,cin,w1); assign c_out=w3||w2; endmodule testbench: module t_Add (); wire sum, c_out; reg a, b,cin; ADD_full M1 (c_out,sum,a,b,cin); initial begin $dumpfile ( "dump.vcd" ); $dumpvars ; end initial begin #100 $finish ; end initial begin #10 a= 0 ;b= 0 ;cin= 1 ; #10 b= 1 ; #10 a= 1 ; #10 b= 0 ; end endmodule 2位选择器: module multiplexer ( output mux_out , input sel, a,b); assign mux_out=(sel)?a:b; endmodule testbench: module t_mux (); wire mux_out; reg a, b,sel; multiplexer M1 (mux_out,sel,a,b); initial