📄 multiplier.vhd
字号:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity multiplier is
generic(k:positive:=8); --input the number of multiplicand(or multiplier)
port(
M,multiplier:in std_logic_vector((k-1) downto 0);
reset,clk:in std_logic;
result:out std_logic_vector((2*k-1) downto 0);
done:out std_logic);
end multiplier;
architecture behave of multiplier is
signal A,Q:std_logic_vector((k-1) downto 0);
signal count:integer range 0 to k;
signal step,qq:std_logic;
begin
process(clk)
begin
if reset='1' then
A<=(others=>'0');
qq<='0';
Q<=multiplier;
result<=(others=>'0');
count<=k;
step<='0';
done<='0';
elsif(clk'event and clk='1') then
if(count/=0) then
if step='0' then
if Q(0)='1' and qq='0' then
A<=A-M;
elsif Q(0)='0' and qq='1' then
A<=A+M;
end if;
step<='1';
elsif step='1' then
qq<=Q(0);
Q<=A(0)&Q((k-1) downto 1);
A((k-2) downto 0)<=A((k-1) downto 1);
count<=count-1;
step<='0';
end if;
else
result<=A&Q;
done<='1';
end if;
end if;
end process;
end behave;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -