Professional Documents
Culture Documents
Multiplier behavioral
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 10:36:52 05/22/2021
-- Design Name:
-- Module Name: multiplier16x16 - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
entity multiplier is
generic (N: integer; M: integer);
port ( a : in std_logic_vector(N-1 downto 0);
b : in std_logic_vector(M-1 downto 0);
prod : out std_logic_vector(M+N-1 downto 0) );
end entity multiplier;
component mult is
port (
a : in std_logic;
b : in std_logic;
pin : in std_logic;
cin : in std_logic;
pout : out std_logic;
cout : out std_logic );
end component;
type mem_word is array (0 to M-1) of std_logic_vector(N-1 downto 0);
signal cin : mem_word;
signal cout : mem_word;
signal pin : mem_word;
signal pout : mem_word;
begin
m_loop: for i in 0 to M-1 generate
n_loop: for j in 0 to N-1 generate
mult_inst : mult
port map (
a => a(j),
b => b(i),
pin => pin(i)(j),
cin => cin(i)(j),
pout => pout(i)(j),
cout => cout(i)(j) );
end generate;
end generate;
cin_init: for j in 0 to N-1 generate
cin(0)(j) <= '0';
end generate;
end behavioral;
Mult instances
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 10:48:19 05/21/2021
-- Design Name:
-- Module Name: mult - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
entity mult is
port ( a : in std_logic;
b : in std_logic;
pin : in std_logic;
cin : in std_logic;
pout : out std_logic;
cout : out std_logic );
end mult;
A -0101010101010101
B -1010101010101010
--------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 21:26:57 05/23/2021
-- Design Name:
-- Module Name: E:/Users/Multiplier32_bit/test16x16.vhd
-- Project Name: Multiplier32_bit
-- Target Device:
-- Tool versions:
-- Description:
--
-- VHDL Test Bench Created by ISE for module: multiplier
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
-- Notes:
-- This testbench has been automatically generated using types std_logic and
-- std_logic_vector for the ports of the unit under test. Xilinx recommends
-- that these types always be used for the top-level I/O of a design in order
-- to guarantee that the testbench will bind correctly to the post-implementation
-- simulation model.
--------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity test16x16 is
end test16x16;
-- signals
signal a : std_logic_vector(15 downto 0) :="0101010101010101";
signal b : std_logic_vector(15 downto 0) :="1010101010101010";
signal answer : std_logic_vector(31 downto 0);
signal correct : std_logic;
begin
dut: multiplier
generic map (
M => 16,
N => 16 )
port map (
a => a,
b => b,
prod => answer );
-- Stimulus process
stim_proc: process
begin
wait for 1 ns;
a <= a + 1;
if a = "0" then
b <= b + 1;
end if;
end process;
-- Check results
correct <= '1' when to_integer(unsigned(a))*to_integer(unsigned(b)) =
to_integer(unsigned(answer)) else '0';
end behavioral;
Output :