Professional Documents
Culture Documents
HHGFHG
HHGFHG
HHGFHG
2 u
se IEEE.STD_LOGIC_1164.ALL;
3 use IEEE. NUMERIC_STD.ALL;
4 entity Divider is
5 Port (clk, reset : in STD_LOGIC;
6 start : in STD_LOGIC;
7 m : in STD_LOGIC_VECTOR (15 downto 0); -- Input for dividend
8 n : in STD_LOGIC_VECTOR (7 downto 0); -- Input for divisor
9 quotient : out STD_LOGIC_VECTOR (7 downto 0); -- Output for
quotient
10 remainder : out STD_LOGIC_VECTOR (7 downto 0); -- Output for
remainder
11 ready, ovfl : out STD_LOGIC); -- Indicates end of algorithm and overflow
condition
12 end Divider;
23 begin
24 --control path: registers of the FSM
25 process(clk, reset)
26 begin
27 if (reset='1') then
28 state_reg <= idle;
29 elsif (clk'event and clk='1') then
30 state_reg <= state_next;
31 end if;
32 end process;
33 --control path: the logic that determines the next state of the FSM (this
part of
34 --the code is written based on the green hexagons of Figure 3)
35 process(state_reg, start, m, n, i_next)
36 begin
37 case state_reg is
38 when idle =>
39 if ( start='1' ) then
40 if ( m(15 downto 8) < n ) then
41 state_next <= shift;
42 else
43 state_next <= idle;
44 end if;
45 else
46 state_next <= idle;
47 end if;
50 when op =>
51 if ( i_next = "1000" ) then
52 state_next <= idle;
53 else
54 state_next <= shift;
55 end if;
56 end case;
57 end process;