2020年4月12日 星期日

1 bit Full adder 全加器 (Gate level)

1 bit Full adder 全加器 (Gate level)




//=========================================
//定義一位元全加器
//(A ⊕ B) ⊕ Carry_in.  == Sum
// (A.B) or ( Carry_in A) or (A.C) === Carry_out
//=========================================
module Full_Adder(a,b,cin,sum,cout);
//宣告輸出入埠
input a,b,cin;

output sum,cout;

//宣告內部接線
wire net1,net2,net3;

xor u0(sum, a, b, cin);
and u1(net1, a, b);
and u2(net2, b, cin);
and u3(net3, cin, a);
or u4 (cout, net1, net2, net3);
endmodule


/* 
Full Adder Module for bit Addition 
*/
`timescale 100ns / 100ps 
 
module TB; 
/*
module Full_Adder (a,b,cin,sum,cout);
input a,b,cin;
output sum,cout;
*/
 
reg a;
reg b;
reg cin;

wire sum,cout;

Full_Adder UUT (a,b,cin,sum,cout);
 
initial
begin
a=1'b0; b=1'b0; cin=1'b0;
#5
a=1'b0; b=1'b0; cin=1'b1;
#5
a=1'b0; b=1'b1; cin=1'b0;
#5
a=1'b0; b=1'b1; cin=1'b1;
#5
a=1'b1; b=1'b0; cin=1'b0;
#5
a=1'b1; b=1'b0; cin=1'b1;
#5
a=1'b1; b=1'b1; cin=1'b0;
#5
a=1'b1; b=1'b1; cin=1'b1;
   
#5
$stop;
        
end
 
endmodule

沒有留言:

張貼留言

2024產專班 作業2 (純模擬)

2024產專班 作業2  (純模擬) 1) LED ON,OFF,TIMER,FLASH 模擬 (switch 控制) 2)RFID卡號模擬 (buttom  模擬RFID UID(不從ESP32) Node-Red 程式 [{"id":"d8886...