32-bit Ripple Carry Adder이다.



rca.vhd

library ieee;
use ieee.std_logic_1164.all;

entity dff is
	port ( d : IN std_logic;
		clk : IN std_logic;
		set, rst : IN std_logic;
		q : OUT std_logic );
end dff;

architecture arch_dff of dff is
begin
	process_dff : process(clk) is
	begin
		if ( rst = '1' ) then
			q <= '0';
		elsif ( set = '1' ) then
			q <= '1';
		elsif ( clk = '1' and clk'event ) then
			q <= d;
		end if;
	end process;
end arch_dff;






rca_tb.vhd

library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;

entity rca_tb is
end rca_tb;

architecture arch_rca_tb of rca_tb is
	component rca is
		port ( a, b : IN std_logic_vector ( 31 downto 0 );
			cin : IN std_logic;
			s : OUT std_logic_vector (31 downto 0);
			cout : OUT std_logic );
	end component;

	signal input_a : std_logic_vector (31 downto 0) := "00000000000000000000000000000000";
	signal input_b : std_logic_vector (31 downto 0) := "11111111111111111111111111111111";
	signal input_cin : std_logic;
	signal output_s : std_logic_vector (31 downto 0);
	signal output_cout : std_logic;

begin
	rca_port_map : rca port map ( input_a, input_b, input_cin, output_s, output_cout );
	
	process_a : process begin
		input_a <= unsigned(input_a) + 1;
		wait for 10 ns;
	end process;

	process_b : process begin
		input_b <= unsigned(input_b) - 1;
		wait for 10 ns;
	end process;

	process_cin: process begin
		input_cin <= '0';
		wait for 100 ns;
		input_cin <= '1';
		wait for 100 ns;
	end process;

end arch_rca_tb;


10 ns의 간격을 두고 input_a는 1씩 더하며 input_b는 1씩 빼주기 때문에 더한 값은 언제나 "11111111111111111111111111111111"이 된다.

여기서 변수는 당연하게도 맨 처음 올라오는 캐리 비트인 input_cin이며, 이 값이 1일 경우 오버플로우가 일어나 output_s는 모든 비트가 0이 되고, output_cout이 1이 된다.




위는 이 글의 소스 그대로 컴파일하여 시뮬레이션을 돌려 본 결과이다.

5 ns 마다 input_cin이 0, 1을 왔다갔다 하기 때문에 output_s와 output_cout 도 마찬가지로 각각 0, 1을 왔다갔다 한다.



이것은 input_cin의 딜레이를 100 ns로 늘려보았을 때의 결과이다.

보다시피 input_cin이 0인 구간에서는 input_a + input_b 는 항상 "11111111111111111111111111111111"로 고정인 것을 알 수 있다.

input_cin이 1이 되면 자연스럽게 output_s는 모든 비트가 0이 되고 output_cout은 1이 된다.

'Programming' 카테고리의 다른 글

[VHDL] 4-bit Carry Select Adder  (0) 2016.02.17
[VHDL] 4 to 1 Multiplexer  (0) 2016.02.15
[VHDL] Full Adder  (0) 2016.02.11
[VHDL] D Flip-Flop  (0) 2016.02.11
파이썬 웹 이미지 크롤러 (GUI)  (0) 2016.02.03
블로그 이미지

__미니__

E-mail : skyclad0x7b7@gmail.com 나와 계약해서 슈퍼 하-카가 되어 주지 않을래?

,