2019年12月28日 星期六

Verilog code for the full adder

Verilog code for the full adder







module Full_Adder( 
  input X1, X2, Cin, 
  output S, Cout
  );  
 wire a1, a2, a3;    
 
 xor u1(a1,X1,X2);
 and u2(a2,X1,X2);
 and u3(a3,a1,Cin);
 or u4(Cout,a2,a3);
 xor u5(S,a1,Cin);
  
endmodule  


// 時間單位 100ns, 時間精確度100 ps
`timescale 100ns/100ps
module Test_bench;
reg t_X1 ,t_X2 ,t_Cin = 1'b0;  //  暫存器資料初值為‘0’
wire t_S ,t_Cout ;
integer i;

Full_Adder  DUT(.X1(t_X1), .X2(t_X2), .Cin(t_Cin),.S(t_S), .Cout(t_Cout));
// initial程序結構區塊, 產生A、B輸入信號波形
initial begin
    $monitor(t_X1 ,t_X2, t_Cin ,t_S ,t_Cout);
    for (i=0; i<8; i=i+1) begin
        {t_X1,t_X2,t_Cin} = i;
        #20;
    end
end

initial
begin
  #160;   // 模擬終止時間  400 ns
    $stop;
end

endmodule

沒有留言:

張貼留言

Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3

  Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3 AngularJS 實例 <!DOCTYPE html> <html> <head> <meta charse...