Advertisement
LucaSkywalker

IntMult.vhd

Nov 28th, 2020
695
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.16 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.std_logic_1164.all;
  3. --use IEEE.std_logic_arith.all;
  4. use IEEE.std_logic_misc.all;
  5. use IEEE.std_logic_unsigned.all;
  6.  
  7. entity IntMult is
  8.     Port (  Clk_in: IN STD_LOGIC;
  9.                 async_rst: IN STD_LOGIC;
  10.                 mult_start_in: IN STD_LOGIC;
  11.                 multiplicand_in: IN STD_LOGIC_VECTOR(3 DOWNTO 0);
  12.                 multiplier_in: IN STD_LOGIC_VECTOR(3 DOWNTO 0);
  13.                 mult_result_out: OUT STD_LOGIC_VECTOR(7 DOWNTO 0);
  14.                 mult_ready_out: OUT STD_LOGIC);
  15. end IntMult;
  16.  
  17. architecture Behavioral of IntMult is
  18.     begin
  19.     Main: process(Clk_in, async_rst)
  20.     variable count : STD_LOGIC_VECTOR (2 DOWNTO 0);
  21.      variable Q : STD_LOGIC_VECTOR(7 DOWNTO 0);
  22.      variable M : STD_LOGIC_VECTOR(3 DOWNTO 0);
  23.      variable C : STD_LOGIC_VECTOR(7 DOWNTO 0);
  24.      variable A : STD_LOGIC_VECTOR(7 DOWNTO 0);
  25.         begin
  26.             if async_rst = '1' then
  27.             count := "000";
  28.             Q := "00000000";
  29.             M := "0000";
  30.             A := "00000000";
  31.             elsif Rising_Edge(Clk_in) then
  32.                 if mult_start_in = '1' then
  33.                     count := "000";
  34.                     Q := "0000" + multiplier_in;
  35.                     M := multiplicand_in;
  36.                     C := "00000000";
  37.                     A := "00000000";
  38.                     mult_result_out <= A;
  39.                     mult_ready_out <= '0';
  40.                 elsif count = "000" then
  41.                     mult_ready_out <= '0';
  42.                     if M(0) = '1' then
  43.                         A := A + Q;
  44.                     end if;
  45.                     mult_result_out <= A;
  46.                     count := count + 1;
  47.                     Q(7 DOWNTO 1) := Q(6 DOWNTO 0) + '0';
  48.                 elsif count = "001" then
  49.                     mult_ready_out <= '0';
  50.                     if M(1) = '1' then
  51.                         A := A + Q;
  52.                     end if;
  53.                     mult_result_out <= A;
  54.                     count := count + 1;
  55.                     Q(7 DOWNTO 1) := Q(6 DOWNTO 0) + '0';
  56.                 elsif count = "010" then
  57.                     mult_ready_out <= '0';
  58.                     if M(2) = '1' then
  59.                         A := A + Q;
  60.                     end if;
  61.                     mult_result_out <= A;
  62.                     count := count + 1;
  63.                     Q(7 DOWNTO 1) := Q(6 DOWNTO 0) + '0';
  64.                 elsif count = "011" then
  65.                     mult_ready_out <= '0';
  66.                     if M(3) = '1' then
  67.                         A := A + Q;
  68.                     end if;
  69.                     mult_result_out <= A;
  70.                     count := count + 1;
  71.                 elsif count = "100" then
  72.                     A := A + Q;
  73.                     A := not A;
  74.                     mult_ready_out <= '1';
  75.                     mult_result_out <= A;
  76.                     count := count + 1;
  77.                 end if;
  78.             end if;
  79.         end process Main;
  80. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement