LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL; USE IEEE.STD_LOGIC_ARITH.ALL ; USE IEEE.STD_LOGIC_UNSIGNED.ALL ; ENTITY dividi IS PORT( clk, init, start: IN STD_LOGIC; ready: OUT STD_LOGIC; zaehler: IN STD_LOGIC_VECTOR (63 DOWNTO 0); nenner: IN STD_LOGIC_VECTOR (63 DOWNTO 0); quotient: OUT STD_LOGIC_VECTOR (63 DOWNTO 0); rest: OUT STD_LOGIC_VECTOR (63 DOWNTO 0)); END dividi; ARCHITECTURE behav OF dividi IS BEGIN PROCESS VARIABLE zaehler_int: STD_LOGIC_VECTOR (63 DOWNTO 0); VARIABLE nenner_int: STD_LOGIC_VECTOR (63 DOWNTO 0); VARIABLE accu: STD_LOGIC_VECTOR (63 DOWNTO 0); VARIABLE x,y,z: integer RANGE 0 to 70; VARIABLE base_index: STD_LOGIC_VECTOR (63 DOWNTO 0); VARIABLE ready_s: STD_LOGIC; VARIABLE quotient_int: STD_LOGIC_VECTOR (63 DOWNTO 0); VARIABLE werte_da: STD_LOGIC; VARIABLE nl: STD_LOGIC; BEGIN WAIT UNTIL clk='1'; IF init='1' THEN ready_s:='0'; werte_da:='0'; nl:='0'; END IF; ready <= '0'; IF start = '1' THEN zaehler_int:=zaehler; nenner_int:=nenner; FOR i IN 0 TO 63 LOOP IF zaehler_int(i) = '1' THEN x := i ; END IF; END LOOP; FOR j IN 0 TO 63 LOOP IF nenner_int(j) = '1' THEN y := j ; END IF; END LOOP; IF y>x THEN x:=y; nl := '1'; ELSE z:=x-y; nl := '0'; END IF; accu:="0000000000000000000000000000000000000000000000000000000000000000"; base_index:="0000000000000000000000000000000000000000000000000000000000000001"; quotient_int:="0000000000000000000000000000000000000000000000000000000000000000"; ready_s := '0'; werte_da := '1'; ELSIF ready_s='1' THEN IF nl='1' THEN quotient<="0000000000000000000000000000000000000000000000000000000000000000"; ELSE quotient<=quotient_int; END IF; ready <= '1'; werte_da := '0'; ready_s := '0'; ELSIF werte_da = '1' THEN --WHILE z>0 LOOP FOR i IN 0 TO 63 LOOP IF z>0 THEN base_index(63 downto 1):= base_index(62 downto 0); base_index(0):='0'; nenner_int(63 downto 1):= nenner_int(62 downto 0); nenner_int(0):='0'; z:=z-1; END IF; END LOOP; accu:=zaehler_int-nenner_int; IF accu(63)='1' THEN IF base_index="0000000000000000000000000000000000000000000000000000000000000001" THEN ready_s:='1'; rest <= nenner_int + accu; ELSE base_index(62 downto 0):= base_index(63 downto 1); base_index(63):='0'; nenner_int(62 downto 0):= nenner_int(63 downto 1); nenner_int(63):='0'; END IF; ELSE zaehler_int:=accu; quotient_int:=quotient_int+base_index; base_index(62 downto 0):= base_index(63 downto 1); base_index(63):='0'; nenner_int(62 downto 0):= nenner_int(63 downto 1); nenner_int(63):='0'; IF base_index="0000000000000000000000000000000000000000000000000000000000000000" THEN ready_s:='1'; rest <= accu; END IF; END IF; END IF; END PROCESS; END behav ;