-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRestoring_Division.vhd
More file actions
116 lines (96 loc) · 3.01 KB
/
Copy pathRestoring_Division.vhd
File metadata and controls
116 lines (96 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Create Date: 08:35:07 11/27/2018
-- Design Name:
-- Module Name: restoring_division - Behavioral
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Revision 0.01 - File Created
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity restoring_division is
Port(
M : in std_logic_vector(15 downto 0);
Q : in std_logic_vector(31 downto 0);
A : out std_logic_vector(15 downto 0);
Q_out : out std_logic_vector(31 downto 0);
clk : in std_logic
);
end entity restoring_division;
architecture Behavioral of restoring_division is
type state_t is (shift_left_prime,A_minus_M,shift_left , restore_A , initial_state , split_AQ,assign_Q0,decrease_N,check_if_N_is_ZERO,finish_state);
signal state : state_t := initial_state;
signal next_state : state_t := shift_left;
signal AQ : std_logic_vector(47 downto 0);
signal A_temp : std_logic_vector(15 downto 0);
signal Q_temp : std_logic_vector(31 downto 0);
signal N : std_logic_vector(5 downto 0);
begin
CMB : process(state)
begin
case state is
when initial_state =>
N <= "100000";
A_temp <= "0000000000000000";
--AQ <= "0000000000000000" & Q;
AQ <= "0000000000000000" & "00000000000000000000000000001011";
--Q_temp <= Q ;
Q_temp <= "00000000000000000000000000001111" ;
next_state <= shift_left;
when shift_left =>
AQ <= A_temp & Q_temp;
next_state <= shift_left_prime;
when shift_left_prime =>
AQ <= AQ(46 downto 0) & '0';
next_state <= split_AQ;
when split_AQ =>
A_temp <= AQ(47 downto 32);
Q_temp <= AQ(31 downto 0);
next_state <= A_minus_M;
when A_minus_M =>
A_temp <= std_logic_vector(unsigned(A_temp) - unsigned(M));
next_state <= assign_Q0;
when assign_Q0 =>
if(A_temp(15) = '1') then
Q_temp(0) <= '0';
next_state <= restore_A;
else
Q_temp(0) <= '1';
next_state <= decrease_N;
end if;
when restore_A =>
A_temp <= std_logic_vector(unsigned(A_temp) + unsigned(M));
next_state <= decrease_N;
when decrease_N =>
N <=std_logic_vector(unsigned(N) - "0001");
next_state <= check_if_N_is_ZERO;
when check_if_N_is_ZERO =>
if(N = "000000") then
next_state <= finish_state;
else
next_state <= shift_left;
end if;
when finish_state =>
Q_out <= Q_temp;
A <= A_temp;
end case;
end process;
REG : process(clk)
begin
if(clk'event and clk = '1') then
state <= next_state;
end if;
end process;
end Behavioral;