My four bit multiplier described in the code below enters an infinite loop when I try to test it via a simulation in Vivado 2022.2. The implementation of the multiplier is "Shift-and-Add Multiplication". The test bench vhdl code is written correctly.
When I cancel the simulation, the application allows me to step in like a debugger, and it seems like the "while" loop runs infinitely, because N is not decremented. I searched for answers and I also added the sensitivity list, and it still shows the same problem.
Do you have any ideas as to why the while does not stop and N is not decremented? Or if it is any other problem somewhere else?
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity four_bit_multiplier is
Port ( x : in STD_LOGIC_VECTOR(3 downto 0);
y : in STD_LOGIC_VECTOR(3 downto 0);
result : out STD_LOGIC_VECTOR(7 downto 0) );
end four_bit_multiplier;
architecture Behavioral of four_bit_multiplier is
component eight_bit_adder is
Port (x : in STD_LOGIC_VECTOR(7 downto 0);
y : in STD_LOGIC_VECTOR(7 downto 0);
c_in: in STD_LOGIC;
c_out: out STD_LOGIC;
sum : out STD_LOGIC_VECTOR(7 downto 0) );
end component;
signal B : STD_LOGIC_VECTOR(7 downto 0);
signal Q : STD_LOGIC_VECTOR(7 downto 0);
signal A : STD_LOGIC_VECTOR(7 downto 0) := x"00";
signal adder_out : STD_LOGIC_VECTOR(7 downto 0);
signal c_out : STD_LOGIC;
signal N: integer := 4;
begin
p1: eight_bit_adder port map(B, A, '0', c_out, adder_out);
process(x, y, B, N, Q, adder_out)
begin
B <= "0000" & x;
Q <= "0000" & y;
while N > 0 loop
if Q(0) = '1' then
A <= adder_out;
end if;
B <= B(6 downto 0) & '0';
Q <= '0' & Q(7 downto 1);
N <= N - 1;
end loop;
result <= A;
end process;
end Behavioral;
Remember that VHDL is a description language, not a programming language. It includes such features, though, but only for simulation.
Loops with
while
are generally not synthesizable. Instead, use afor
loop.