此代码使两个二进制数的除法运算每个数字为4位,我需要修改此代码以使输出分数结果为例,例如,说明我的想法1010(10)除以0011(3)= 11.010101(3.3333) ),那么需要修改什么部分才能在电路输出中以二进制形式显示结果 预先谢谢你
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_unsigned.All;
entity division4bits is
generic(SIZE: INTEGER := 4);
port(reset: in STD_LOGIC;
en: in STD_LOGIC;
clk: in STD_LOGIC;
num: in STD_LOGIC_VECTOR((SIZE - 1) downto 0);
den: in STD_LOGIC_VECTOR((SIZE - 1) downto 0);
result: out STD_LOGIC_VECTOR((SIZE - 1) downto 0);
remender: out STD_LOGIC_VECTOR((SIZE - 1) downto 0)
);
end division4bits;
architecture Behavioral of division4bits is
signal buf: STD_LOGIC_VECTOR((2 * SIZE - 1) downto 0);
signal dbuf: STD_LOGIC_VECTOR((SIZE - 1) downto 0);
signal sm: INTEGER range 0 to SIZE;
alias buf1 is buf((2 * SIZE - 1) downto SIZE);
alias buf2 is buf((SIZE - 1) downto 0);
begin
p_001: process(reset, en, clk)
begin
if reset = '1' then
result <= (others => '0');
remender <= (others => '0');
sm <= 0;
elsif rising_edge(clk) then
if en = '1' then
case sm is
when 0 =>
buf1 <= (others => '0');
buf2 <= num;
dbuf <= den;
result <= buf2;
remender <= buf1;
sm <= sm + 1;
when others =>
if buf((2 * SIZE - 2) downto (SIZE - 1)) >= dbuf then
buf1 <= '0' & (buf((2 * SIZE - 3) downto (SIZE - 1)) -
dbuf((SIZE - 2) downto 0));
buf2 <= buf2((SIZE - 2) downto 0) & '1';
else
buf <= buf((2 * SIZE - 2) downto 0) & '0';
end if;
if sm /= SIZE then
sm <= sm + 1;
else
sm <= 0;
end if;
end case;
end if;
end if;
end process;
end Behavioral;