ضرب کننده
هدف ما در این برنامه طراحی یک ضرب کننده است.
خروجی برنامه ی اول بر روی LED بوده و خروجی برنامه ی دوم بر روی Seven_Segment است.
برنامه اول
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity NewCode is
Port ( a : in STD_LOGIC_VECTOR (7 downto 0);
b : in STD_LOGIC_VECTOR (7 downto 0);
y : out STD_LOGIC_VECTOR (3 downto 0);
clk1 : in STD_LOGIC ;
clk2 : in STD_LOGIC);
end NewCode;
architecture Behavioral of NewCode is
signal clk :std_logic;
signal f :std_logic_vector (3 downto 0);
signal counter :std_logic_vector ( 1 downto 0):="00";
begin
process (clk1, clk2)
begin
if clk2='1' and clk2' event then
clk <= clk1;
end if;
end process;
Process
begin
if clk='1' and clk'event then
counter <= counter + 1;
end if;
end process;
with counter select
f <= (a(1)&a(0)&b(1)&b(0)) when "00",
(a(3)&a(2)&b(3)&b(2)) when "01",
(a(5)&a(4)&b(5)&b(4)) when "10",
(a(7)&a(6)&b(7)&b(6)) when others;
y <= not (f(1 downto 0) * f(3 downto 2));
end Behavioral;
برنامه دوم
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity NewCode is
Port ( a : in STD_LOGIC_VECTOR (7 downto 0);
b : in STD_LOGIC_VECTOR (7 downto 0);
y : out STD_LOGIC_VECTOR (6 downto 0);
clk1 : in STD_LOGIC ;
clk2 : in STD_LOGIC);
end NewCode;
architecture Behavioral of NewCode is
signal clk :std_logic;
signal f :std_logic_vector (3 downto 0);
signal counter :std_logic_vector ( 1 downto 0):="00";
signal t:std_logic_vector(3 downto 0);
signal h:STD_LOGIC_VECTOR (6 downto 0);
begin
process (clk1, clk2)
begin
if clk2='1' and clk2' event then
clk <= clk1;
end if;
end process;
Process
begin
if clk='1' and clk'event then
counter <= counter + 1;
end if;
end process;
with counter select
f <= (a(1)&a(0)&b(1)&b(0)) when "00",
(a(3)&a(2)&b(3)&b(2)) when "01",
(a(5)&a(4)&b(5)&b(4)) when "10",
(a(7)&a(6)&b(7)&b(6)) when others;
t <= (f(1 downto 0) * f(3 downto 2));
with t select
h <= "0111111" when "0000",
"0000110" when "0001",
"1011011" when "0010",
"1001111" when "0011",
"1100110" when "0100",
"1101101" when "0101",
"1111101" when "0110",
"0000111" when "0111",
"1111111" when "1000",
"1101111" when others;
y <=not(h);
end Behavioral;