📄 divider.vhd
字号:
Library ieee;
use ieee.std_logic_1164.ALL;
use ieee.std_logic_arith.ALL;
use ieee.std_logic_unsigned.all;
entity divider is
--generic (DWIDTH : integer := 15);
port (dvdnd_i : in std_logic_vector(15 downto 0); -- Dividend
dvsor_i : in std_logic_vector(15 downto 0); -- Divisor
qutnt_o : out std_logic_vector(15 downto 0); -- Quotient
rmndr_o : out std_logic_vector(15 downto 0)); -- Remainder
end divider;
architecture rtl of divider is
begin -- rtl
-- purpose: Divide dvdnd_i through dvsor_i and deliver the result to qutnt_o
-- and the remainder to rmndr_o.
-- type : combinational
-- inputs : dvdnd_i, dvsor_i
-- outputs: qutnt_o, rmndr_o
p_divide: process (dvdnd_i, dvsor_i)
variable v_actl_dvdnd : unsigned(15 downto 0);
variable v_dffrnc : unsigned(15 downto 0);
variable v_qutnt : unsigned(15 downto 0);
begin -- process p_divide
v_actl_dvdnd := unsigned(dvdnd_i);
for i in 15 downto 0 loop
-- If the divisor can be subtracted from this part of the dividend, then
-- the corresponding bit of the quotient has to be 1, otherwise 0.
if CONV_STD_LOGIC_VECTOR(v_actl_dvdnd(15 downto i),16) >=dvsor_i then
-- Divisor can be subtracted
v_qutnt(i) := '1';
v_dffrnc := CONV_UNSIGNED(v_actl_dvdnd(15 downto i),16) - unsigned(dvsor_i);
-- As long as this is not the last step of calculation, shift the
-- intermediate result.
if i /= 0 then
v_actl_dvdnd(15 downto i) := v_dffrnc(15-i downto 0);
v_actl_dvdnd(i-1) := dvdnd_i(i-1);
end if;
else
-- Divisor is greater than this part of the dividend.
v_qutnt(i) := '0';
v_dffrnc := CONV_UNSIGNED(v_actl_dvdnd(15 downto i),16);
end if;
end loop; -- i
rmndr_o <= std_logic_vector(v_dffrnc);
qutnt_o <= std_logic_vector(v_qutnt);
end process p_divide;
end rtl;
configuration comb_divider_rtl_cfg of divider is
for rtl
end for;
end comb_divider_rtl_cfg;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -