Saturday, June 29, 2013

Write VHDL code to realize Half-subtractor

Aim : Write VHDL code to realize Half-subtractor

CODE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

---- Uncomment the following library declaration if instantiating
---- any Xilinx primitives in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity half_subtractor is
    Port ( a : in  STD_LOGIC;
           b : in  STD_LOGIC;
           di : out  STD_LOGIC;
           bo : out  STD_LOGIC);
end half_subtractor;

architecture Behavioral of half_subtractor is

begin
process(a,b)
begin
if (a='0' and b='0') then
            di<='0';
            bo<='0';
elsif (a='0' and b='1') then
            di<='1';
            bo<='1';
elsif (a='1' and b='0') then
            di<='1';
            bo<='0';
elsif (a='1' and b='1') then
            di<='0';
            bo<='0';
else
            null;
end if;
end process;


end Behavioral;

No comments:

Post a Comment