Lec2 Example
Lec2 Example
library ieee;
use ieee.std_logic_1164.all;
entity AND_ent is
port( x: in std_logic;
y: in std_logic;
F: out std_logic
);
end AND_ent;
process(x, y)
begin
-- compare to truth table
if ((x='1') and (y='1')) then
F <= '1';
else
F <= '0';
end if;
end process;
end behav1;
--------------------------------------------
architecture behav2 of AND_ent is
begin
F <= x and y;
end behav2;
Example_2// OR gate
library ieee;
use ieee.std_logic_1164.all;
entity OR_ent is
port( x: in std_logic;
y: in std_logic;
F: out std_logic
);
end OR_ent;
process(x, y)
begin
-- compare to truth table
if ((x='0') and (y='0')) then
F <= '0';
else
F <= '1';
end if;
end process;
end OR_arch;
-------------------------------------------------------------------------
architecture OR_beh of OR_ent is
begin
F <= x or y;
end OR_beh;
Example_3//X OR gate
library ieee;
use ieee.std_logic_1164.all;
entity XOR_ent is
port( x: in std_logic;
y: in std_logic;
F: out std_logic
);
end XOR_ent;
process(x, y)
begin
-- compare to truth table
if (x/=y) then
F <= '1';
else
F <= '0';
end if;
end process;
end behv1;
F <= x xor y;
end behv2;
Example_4//NOR gate
library ieee;
use ieee.std_logic_1164.all;
entity NOR_ent is
port( x: in std_logic;
y: in std_logic;
F: out std_logic
);
end NOR_ent;
process(x, y)
begin
-- compare to truth table
if (x='0' and y='0') then
F <= '1';
else
F <= '0';
end if;
end process;
end behv1;
F <= x nor y;
end behv2;
Example_5//NAND gate
library ieee;
use ieee.std_logic_1164.all;
entity NAND_ent is
port( x: in std_logic;
y: in std_logic;
F: out std_logic
);
end NAND_ent;
process(x, y)
begin
-- compare to truth table
if (x='1' and y='1') then
F <= '0';
else
F <= '1';
end if;
end process;
end behv1;
F <= x nand y;
end behv2;
Example_6//XNOR gate
library ieee;
use ieee.std_logic_1164.all;
--------------------------------------
entity XNOR_ent is
port( x: in std_logic;
y: in std_logic;
F: out std_logic
);
end XNOR_ent;
---------------------------------------
process(x, y)
begin
-- compare to truth table
if (x/=y) then
F <= '0';
else
F <= '1';
end if;
end process;
end behv1;
F <= x xnor y;
end behv2;