--入力
signal dev_A: std_logic_vector(19 downto 0);
signal dev_B: std_logic_vector(10 downto 0);
--出力
signal dev_out: std_logic_vector(9 downto 0);
--コントロール
signal load_dev: std_logic; -- データを割り算器にロード
signal busy_dev: std_logic; -- 割り算処理中
signal fin_dev: std_logic; -- 割り算処理終了
--内部レジスタ
signal dev_A2: std_logic_vector(19 downto 0);
signal dev_count: std_logic_vector(3 downto 0);
------------------------------------------------------
--使用するプロセス内に、ここの部分を入れてください。
------------------------------------------------------
div_A <= "割られる数";
div_B <= "割る数";
cls_dev <= '0';
load_dev <= '1';
if fin_dev='1' and load_dev='1' then
"回答用logic_vector"<=dev_out;
load_dev<='0';
flag <='1'; -- 逐次的に処理がしたい場合は、
フラッグを使用して処理をとばさないようにする。
cls_dev <='1';
end if;
---------------------------
--割り算メインプロセス
---------------------------
process(clk)
begin
if reset ='0' then
busy_dev <='0';
fin_dev <='0';
elsif clk'event and clk='1' then
if load_dev ='1' then
if busy_dev = '0' and fin_dev = '0' then
dev_count <="0000";
dev_out <="0000000000";
busy_dev <= '1';
dev_A2 <= dev_A;
elsif fin_dev ='0' and dev_count <= "1011" then
dev_count <= dev_count + 1;
end if;
if dev_count = "0001" and dev_A2(19 downto 9) >= dev_B then
dev_out(9) <='1';
dev_A2(19 downto 9) <= dev_A2(19 downto 9) - dev_B;
end if;
if dev_count = "0010" and dev_A2(19 downto 8) >= ('0' & dev_B) then
dev_out(8) <='1';
dev_A2(19 downto 8) <= dev_A2(19 downto 8) - ('0' & dev_B);
end if;
if dev_count = "0011" and dev_A2(19 downto 7) >= ("00" & dev_B) then
dev_out(7) <='1';
dev_A2(19 downto 7) <= dev_A2(19 downto 7) - ("00" & dev_B);
end if;
if dev_count = "0100" and dev_A2(19 downto 6) >= ("000" & dev_B) then
dev_out(6) <='1';
dev_A2(19 downto 6) <= dev_A2(19 downto 6) - ("000" & dev_B);
end if;
if dev_count = "0101" and dev_A2(19 downto 5) >= ("0000" & dev_B) then
dev_out(5) <= '1';
dev_A2(19 downto 5) <= dev_A2(19 downto 5) - ("0000" & dev_B);
end if;
if dev_count = "0110" and dev_A2(19 downto 4) >= ("00000" & dev_B) then
dev_out(4) <='1';
dev_A2(19 downto 4) <= dev_A2(19 downto 4) - ("00000" & dev_B);
end if;
if dev_count = "0111" and dev_A2(19 downto 3) >= ("000000" & dev_B) then
dev_out(3) <='1';
dev_A2(19 downto 3) <= dev_A2(19 downto 3) - ("000000" & dev_B);
end if;
if dev_count = "1000" and dev_A2(19 downto 2) >= ("0000000" & dev_B) then
dev_out(2) <='1';
dev_A2(19 downto 2) <= dev_A2(19 downto 2) - ("0000000" & dev_B);
end if;
if dev_count = "1001" and dev_A2(19 downto 1) >= ("00000000" & dev_B) then
dev_out(1) <='1';
dev_A2(19 downto 1) <= dev_A2(19 downto 1) - ("00000000" & dev_B);
end if;
if dev_count = "1010" and dev_A2(19 downto 0) >= ("000000000" & dev_B) then
dev_out(0) <='1';
dev_A2(19 downto 0) <= dev_A2(19 downto 0) - ("000000000" & dev_B);
end if;
if dev_count = "1011" then
busy_dev <= '0';
fin_dev <='1';
end if;
end if;
if cls_dev = '1' then
fin_dev <= '0';
end if;
end if;
end process;
|