Skip to content

Instantly share code, notes, and snippets.

@moaminsharifi
Created October 10, 2020 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moaminsharifi/3c7afa8c281e4afdef042cc2ae2b32e3 to your computer and use it in GitHub Desktop.
Save moaminsharifi/3c7afa8c281e4afdef042cc2ae2b32e3 to your computer and use it in GitHub Desktop.
Half Adder Module in VHDL (from: www.nandland.com)
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity half_adder is
port (
i_bit1 : in std_logic;
i_bit2 : in std_logic;
--
o_sum : out std_logic;
o_carry : out std_logic
);
end half_adder;
architecture rtl of half_adder is
begin
o_sum <= i_bit1 xor i_bit2;
o_carry <= i_bit1 and i_bit2;
end rtl;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity half_adder_tb is
end half_adder_tb;
architecture behave of half_adder_tb is
signal r_BIT1 : std_logic := '0';
signal r_BIT2 : std_logic := '0';
signal w_SUM : std_logic;
signal w_CARRY : std_logic;
begin
UUT : entity work.half_adder -- uses default binding
port map (
i_bit1 => r_BIT1,
i_bit2 => r_BIT2,
o_sum => w_SUM,
o_carry => w_CARRY
);
process is
begin
r_BIT1 <= '0';
r_BIT2 <= '0';
wait for 10 ns;
r_BIT1 <= '0';
r_BIT2 <= '1';
wait for 10 ns;
r_BIT1 <= '1';
r_BIT2 <= '0';
wait for 10 ns;
r_BIT1 <= '1';
r_BIT2 <= '1';
wait for 10 ns;
end process;
end behave;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment