내가 베릴로그 다시 건드릴 날이 올까
반가산기와 전가산기 #
덧셈을 구현하는 기초적인 논리 회로
반가산기 #
반가산기의 진리표
| A | B | C | S |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 0 |
전가산기 #
Cout = A xor B xor Cin
S = (A and B) or (Cin and(A xor B))
반가산기 2개와 OR 게이트 1개를 이용해서 만들 수 있다.
Verilog 코드 #
//반가산기
module ha ( a ,b ,sum ,cout );
input a ;
wire a ;
input b ;
wire b ;
output sum ;
wire sum ;
output cout ;
wire cout ;
wire cout_bar;
xor(sum,a,b);
nand(cout_bar,a,b);
not(cout,cout_bar);
endmodule
// 반가산기 두개를 연결한 전가산기
module fa1 ( a ,b ,cin ,sum ,cout );
input a ;
wire a ;
input b ;
wire b ;
output cout ;
wire cout ;
output sum ;
wire sum ;
input cin ;
wire ha1cout;
wire ha1sum;
wire ha2cout;
ha ha1(.a(a), .b(b), .sum(ha1sum),
.cout(ha1cout));
ha ha2(.a(cin), .b(ha1sum),
.sum(sum), .cout(ha2cout));
or(cout,ha1cout,ha2cout);
endmodule
다른 방법으로 만든 전가산기
module fa(a,b,cin,sum,cout);
output cout;
input cin;
input a ;
input b;
output sum;
assign sum = a ^ b ^ cin;
assign cout = (a && b)||(cin &&(a ^ b));
endmodule