Programming
[VHDL] Full Adder
__미니__
2016. 2. 11. 23:23
a, b, cin을 입력받아 덧셈의 결과를 s, cout으로 출력해주는 Full Adder이다.
fa.vhd
library ieee; use ieee.std_logic_1164.all; entity fa is port ( a, b, cin : IN std_logic; s, cout : OUT std_logic ); end fa; architecture arch_fa of fa is begin s <= a XOR b XOR cin; cout <= (a AND b) OR (b AND cin) OR (a AND cin); end arch_fa;
fa_tb.vhd
library ieee; use ieee.std_logic_1164.all; entity fa_tb is end fa_tb; architecture arch_fa_tb of fa_tb is signal input_a, input_b, input_cin : std_logic; signal output_s, output_cout : std_logic; component fa is port ( a, b, cin : IN std_logic; s, cout : OUT std_logic ); end component; begin fa_port_map : fa port map ( input_a, input_b, input_cin, output_s, output_cout ); process_a : process begin input_a <= '0'; wait for 20 ns; input_a <= '1'; wait for 10 ns; end process; process_b : process begin input_b <= '1'; wait for 10 ns; input_b <= '0'; wait for 20 ns; end process; process_cin : process begin input_cin <= '1'; wait for 10 ns; input_cin <= '0'; wait for 10 ns; end process; end arch_fa_tb;
이를 여러 개 연결하여 여러 비트의 덧셈연산을 수행할 수 있다.
시뮬레이션을 돌려 본 화면이다.
현재 가리키고 있는 상태는 input_a에 0, input_b에 1, input_cin에 1이 들어가 output_s는 올림되어 0이 되고, output_cout에 1이 들어간 상태로 정상 작동하는 것을 알 수 있다.