4-bit Adder를 Hierarchical modeling과 Structural modeling을 통해 아래와 같이 구현할 것이다. half adder 2개를 불러와 full adder를 구현하고, full adder 4개를 연결하여 4-bit adder를 구현할 수 있다.
1. half adder
module half_adder(x,y,s,c);
input x,y;
output s,c;
xor (s,x,y);
and (c,x,y);
endmodule
2. full adder
module full_adder(x,y,c_in,s,c_out);
input x,y,c_in;
output s,c_out;
wire s1,c1,c2;
half_adder ha1 (x,y,s1,c1);
half_adder ha2 (c_in,s1,s,c2);
or (c_out, c2, c1);
endmodule
3. 4-bit adder
module four_bit_adder(x,y,c_in,sum,c_out);
input [3:0] x,y;
input c_in;
output [3:0] sum;
output c_out;
wire c1, c2, c3;
full_adder fa_1 (x[0], y[0], c_in, sum[0], c1);
full_adder fa_2 (x[1], y[1], c1, sum[1], c2);
full_adder fa_3 (x[2], y[2], c2, sum[2], c3);
full_adder fa_4 (x[3], y[3], c3, sum[3], c_out);
endmodule
4. 시뮬레이션 결과
x = 5, y = 0 - 15, c_in = 0 - 1일 때, 출력값 sum과 c_out이 올바르게 나온것을 확인할 수 있다. 4-bit adder이므로 십진수로 최대 표현할 수 있는 숫자는 15이다. 따라서 5 + 10 + 1 ( a + b + c_in )인 경우 sum = 0, c_out = 1인 것을 확인할 수 있다.
'전자공학 > Verilog' 카테고리의 다른 글
Testbench를 기술하는 방법 (0) | 2020.07.20 |
---|---|
Full Adder & MUX & Decoder ( Structural Modeling ) (0) | 2020.07.17 |
Structural Modeling (0) | 2020.07.17 |