2019年12月28日 星期六

Verilog Half Adder

Verilog Half Adder  

Half Adder Truth Table
ABCarrySum
0000
1001
0101
1110


                                                   





module half_Adder (i_A,i_B,o_sum,o_carry);

  input  i_A;
  input  i_B;
  output o_sum;
  output o_carry;

  assign o_sum   = i_A ^ i_B ;  // bitwise xor
  assign o_carry = i_A & i_B ;  // bitwise and

endmodule // half_adder

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

half_Adder  DUT(.i_A(t_A),.i_B(t_B),.o_sum(t_sum),.o_carry(t_carry));
// initial程序結構區塊, 產生A、B輸入信號波形
initial begin
    $monitor(t_A ,t_B, t_sum ,t_carry);
    for (i=0; i<4; i=i+1) begin
        {t_A ,t_B} = i;
        #20;
    end
end

initial
begin
  #100;   // 模擬終止時間  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...