VHDL Code For Halfadder: - Logic - Xor
VHDL Code For Halfadder: - Logic - Xor
library ieee;
use ieee.std_logic_1164.all;;
entity halfadder is
end halfadder;
component logic_xor is
end component;
component logic_and is
end component;
begin
end structural;
--logic_xor
library ieee;
use ieee.std_logic_1164.all;
entity logic_xor is
end logic_xor;
architecture behavioral of logic_xor is
begin
z <= a xor b;
end behavioral;
--logic_and
library ieee;
use ieee.std_logic_1164.all;
entity logic_and is
end logic_and;
begin
z <= a and b;
end behavioral;
VHDL code for Fulladder
library ieee;
use ieee.std_logic_1164.all ;
entity fulladder is
end fulladder;
component logic_xor is
end component;
component logic_and is
end component;
component logic_or is
end component;
begin
end structural;
--logic_xor
library ieee;
use ieee.std_logic_1164.all;
entity logic_xor is
end logic_xor;
begin
z <= a xor b;
end behavioral;
--logic_and
library ieee;
use ieee.std_logic_1164.all;
entity logic_and is
end logic_and;
begin
z <= a and b;
end behavioral;
--logic_or
library ieee;
use ieee.std_logic_1164.all;
entity logic_or is
end logic_or;
begin
z <= a or b or c ;
end behavioral;
VHDL code for Half-subtractor
entity halfsub is
end halfsub;
component logic_xor is
end component;
component logic_not is
end component;
component logic_and is
end component;
signal s0 : std_logic;
begin
end structural;
--logic_not
library ieee;
use ieee.std_logic_1164.all;
entity logic_not is
begin
z <= not a;
end behavioral;
--logic_xor
library ieee;
use ieee.std_logic_1164.all;
entity logic_xor is
end logic_xor;
begin
z <= a xor b;
end behavioral;
--logic_and
library ieee;
use ieee.std_logic_1164.all;
entity logic_and is
end logic_and;
begin
z <= a and b;
end behavioral;
VHDL code for Full-subtractor
entity fullsub is
end fullsub;
component logic_xor is
end component;
component logic_not is
end component;
component logic_and is
end component;
component logic_or is
end component;
begin
end structural ;
--logic_not
library ieee;
use ieee.std_logic_1164.all;
entity logic_not is
end logic_not;
begin
z <= not a;
end behavioral;
--logic_xor
library ieee;
use ieee.std_logic_1164.all;
entity logic_xor is
end logic_xor;
begin
z <= a xor b;
end behavioral;
--logic_and
library ieee;
use ieee.std_logic_1164.all;
entity logic_and is
end logic_and;
begin
z <= a and b;
end behavioral;
--logic_or
library ieee;
use ieee.std_logic_1164.all;
entity logic_or is
end logic_or;
begin
z <= a or b or c ;
end behavioral;
VHDL code for 4-bit Adder/Subtractor
library ieee ;
use ieee.std_logic_1164.all ;
entity addsub is
m : in std_logic ;
end addsub ;
component logic_xor is
end component ;
component fulladder is
end component ;
begin
end structural ;
--Logic_xor
library ieee ;
use ieee.std_logic_1164.all ;
entity logic_xor is
end logic_xor ;
begin
z <= a xor b ;
end behavioral ;
-- fulladder
library ieee ;
use ieee.std_logic_1164.all ;
entity fulladder is
end fulladder ;
begin
end behavioral ;
VHDL Code for 4-bit BCD Adder
library ieee ;
use ieee.std_logic_1164.all ;
entity bcdadder is
Port ( a, b : in std_logic_vector (3 downto 0) ;
cin : in std_logic ;
end bcdadder ;
architecture structural of bcdadder is
component fulladder is
end component ;
component logic_and is
end component ;
component logic_or is
end component ;
signal s0, s1, s2, s3, s4, s5, s6, s7, c0, c1, c2, c3, c4, c5, c6 : std_logic ;
begin
cout <= s7 ;
end structural ;
--full adder
library ieee ;
use ieee.std_logic_1164.all ;
entity fulladder is
end fulladder ;
begin
end behavioral ;
--logic_and
library ieee ;
use ieee.std_logic_1164.all ;
entity logic_and is
port(a, b: in std_logic ; z : out std_logic) ;
end logic_and ;
architecture behavioral of logic_and is
begin
z <= a and b ;
end behavioral ;
--logic_or
library ieee ;
use ieee.std_logic_1164.all ;
entity logic_or is
port(a, b, c : in std_logic ; z : out std_logic) ;
end logic_or ;
architecture behavioral of logic_or is
begin
z <= a or b or c ;
end behavioral ;
VHDL code for 4 to 1 Multiplexer
library ieee ;
use ieee.std_logic_1164.all ;
entity multiplexer is
port(i0, i1, i2, i3, s0, s1, enable : in std_logic ;
y : out std_logic) ;
end multiplexer ;
architecture structural of multiplexer is
component logic_not is
end component ;
component logic_and is
end component ;
component logic_or is
end component ;
begin
end structural ;
--logic_not
library ieee ;
use ieee.std_logic_1164.all ;
entity logic_not is
port(a : in std_logic ;
z: out std_logic) ;
end logic_not ;
begin
z <= not a ;
end behavioral ;
--logic_and
library ieee ;
use ieee.std_logic_1164.all ;
entity logic_and is
z: out std_logic) ;
end logic_and ;
begin
end behavioral ;
--logic_or
library ieee ;
use ieee.std_logic_1164.all ;
entity logic_or is
z: out std_logic) ;
end logic_or ;
begin
z <= a or b or c or d ;
end behavioral ;
VHDL code for 1 to 4 De-multiplexer
library ieee ;
use ieee.std_logic_1164.all ;
entity demultiplexer is
port(i, s0, s1, enable : in std_logic ;
end demultiplexer ;
architecture structural of demultiplexer is
component logic_not is
end component ;
component logic_and is
end component ;
begin
end structural ;
--logic_not
library ieee ;
use ieee.std_logic_1164.all ;
entity logic_not is
port(a : in std_logic ;
z: out std_logic) ;
end logic_not ;
begin
z <= not a ;
end behavioral ;
--logic_and
library ieee ;
use ieee.std_logic_1164.all ;
entity logic_and is
z: out std_logic) ;
end logic_and ;
begin
end behavioral ;
VHDL code for D-Flipflop
library ieee ;
use ieee.std_logic_1164.all ;
entity dflipflop is
port (d, clock, reset : in std_logic ; q, qbar : out std_logic) ;
end dflipflop ;
architecture behavioral of dflipflop is
signal qs: std_logic;
begin
process (clock, reset)
begin
if reset='1' then
qs <= '0' ;
elsif clock'event and clock = '1' then
qs <= d ;
end if ;
end process ;
q <= qs;
qbar <= not qs ;
end behavioral ;
VHDL code for T-Flipflop
library ieee ;
use ieee.std_logic_1164.all ;
entity tflipflop is
port (t, clock, reset : in std_logic ; q, qbar : out std_logic) ;
end tflipflop ;
architecture behavioral of tflipflop is
signal qs : std_logic;
begin
process (clock, reset)
begin
if reset='1' then
qs <= '0' ;
elsif clock'event and clock = '1' then
case t is
when ‘0’ => qs <= qs ;
when ‘1’ => qs <= not qs ;
when others => qs <= ‘-’ ;
end case ;
end if ;
end process ;
q <= qs;
qbar <= not qs ;
end behavioral ;
VHDL code for SR-Flipflop
library ieee ;
use ieee.std_logic_1164.all ;
entity SRflipflop is
port (s, r, clock, reset : in std_logic ; q, qbar : out std_logic) ;
end SRflipflop ;
architecture behavioral of SRflipflop is
signal qs : std_logic;
begin
process (clock, reset)
variable sr : std_logic_vector (1 downto 0) ;
begin
if reset='1' then
qs <= '0' ;
elsif clock'event and clock = '1' then
sr := (s & r ) ;
case sr is
when “00” => qs <= qs ;
when “01” => qs <= ‘0’ ;
when “10” => qs <= ‘1’ ;
when “11” => qs <= ‘-’ ;
when others => qs <= ‘-’ ;
end case ;
end if ;
end process ;
q <= qs;
qbar <= not qs ;
end behavioral ;
VHDL code for JK-Flipflop
library ieee ;
use ieee.std_logic_1164.all ;
entity JKflipflop is
port (j, k, clock, reset : in std_logic ; q, qbar : out std_logic) ;
end JKflipflop ;
architecture behavioral of JKflipflop is
signal qs : std_logic;
begin
process (clock, reset)
variable jk : std_logic_vector (1 downto 0) ;
begin
if reset='1' then
qs <= '0' ;
elsif clock'event and clock = '1' then
jk := (j & k ) ;
case jk is
when “00” => qs <= qs ;
when “01” => qs <= ‘0’ ;
when “10” => qs <= ‘1’ ;
when “11” => qs <= not qs ;
when others => qs <= ‘-’ ;
end case ;
end if ;
end process ;
q <= qs;
qbar <= not qs;
end behavioral ;
VHDL code for 3-bit Synchronous Up-Counter
library ieee ;
use ieee.std_logic_1164.all ;
entity upcounter is
port (reset, clock : in std_logic ; q : out std_logic_vector (2 downto 0)) ;
end upcounter ;
architecture structural of upcounter is
component tflipflop is
port (t, clock, reset : in std_logic ; q, qbar : out std_logic) ;
end component ;
component logic_and is
port (a, b : in std_logic ; z : out std_logic) ;
end component ;
signal s0, s1, s2, s3, s4, s5, s6 : std_logic ;
begin
C : tflipflop port map ('1', clock, reset, s0, s1) ;
B : tflipflop port map (s0, clock, reset, s2, s3) ;
A : tflipflop port map (s6, clock, reset, s4, s5) ;
g: logic_and port map(s0, s2, s6) ;
q(0) <= s0 ;
q(1) <= s2 ;
q(2) <= s4 ;
end structural ;
--tflipflop
library ieee ;
use ieee.std_logic_1164.all ;
entity tflipflop is
port (t, clock, reset : in std_logic ; q, qbar : out std_logic) ;
end tflipflop ;
architecture behavioral of tflipflop is
signal qs : std_logic;
begin
process (clock, reset)
begin
if reset='1' then
qs <= '0' ;
elsif clock'event and clock = '1' then
case t is
when ‘0’ => qs <= qs ;
when ‘1’ => qs <= not qs ;
when others => qs <= ‘-’ ;
end case ;
end if ;
end process ;
q <= qs;
qbar <= not qs ;
end behavioral ;
--logic_and
library ieee ;
use ieee.std_logic_1164.all ;
entity logic_and is
port(a, b: in std_logic ; z : out std_logic) ;
end logic_and ;
architecture behavioral of logic_and is
begin
z <= a and b ;
end behavioral ;
VHDL code for 3-bit Synchronous Down-Counter
library ieee ;
use ieee.std_logic_1164.all ;
entity downcounter is
port (reset, clock : in std_logic ; q : out std_logic_vector (2 downto 0)) ;
end downcounter ;
architecture structural of downcounter is
component tflipflop is
port (t, clock, reset : in std_logic ; q, qbar : out std_logic) ;
end component ;
component logic_and is
port (a, b : in std_logic ; z : out std_logic) ;
end component ;
signal s0, s1, s2, s3, s4, s5, s6 : std_logic ;
begin
C : tflipflop port map ('1', clock, reset, s0, s1) ;
B : tflipflop port map (s1, clock, reset, s2, s3) ;
A : tflipflop port map (s6, clock, reset, s4, s5) ;
g: logic_and port map(s1, s3, s6) ;
q(0) <= s0 ;
q(1) <= s2 ;
q(2) <= s4 ;
end structural ;
--tflipflop
library ieee ;
use ieee.std_logic_1164.all ;
entity tflipflop is
port (t, clock, reset : in std_logic ; q, qbar : out std_logic) ;
end tflipflop ;
architecture behavioral of tflipflop is
signal qs : std_logic;
begin
process (clock, reset)
begin
if reset='1' then
qs <= '0' ;
elsif clock'event and clock = '1' then
case t is
when ‘0’ => qs <= qs ;
when ‘1’ => qs <= not qs ;
when others => qs <= ‘-’ ;
end case ;
end if ;
end process ;
q <= qs;
qbar <= not qs ;
end behavioral ;
--logic_and
library ieee ;
use ieee.std_logic_1164.all ;
entity logic_and is
port(a, b: in std_logic ; z : out std_logic) ;
end logic_and ;
architecture behavioral of logic_and is
begin
z <= a and b ;
end behavioral ;