Unsigned Divider RTL Model
Unsigned Divider RTL Model
Unsigned Divider RTL Model
Assignment 6 : EE224
----------------------------------------------------------------------------------------------------------------------------------------------------------------
Set quotient to 0
Align leftmost digits in dividend and divisor
Repeat
o If that portion of the dividend above the divisor is greater than or equal to the
divisor
Then subtract divisor from that portion of the dividend and
Concatenate 1 to the right hand end of the quotient
Else concatenate 0 to the right hand end of the quotient
o Shift the divisor one place right
Until dividend is less than the divisor
quotient is correct, dividend is remainder
STOP
qr : DataRegister
generic map(data_width => 8)
port map(qreg_in,qreg,qregEnable,clk);
--result Logic--------resultEnable <= t(4);
quotient_in <= qreg;
remainder_in <= rreg;
quoR : DataRegister
generic map(data_width => 8)
port map(quotient_in,quotient,resultEnable,clk);
remR : DataRegister
generic map(data_width => 8)
port map(remainder_in,remainder,resultEnable,clk);
end architecture;
---------------------------------------------------------------
component dataPath is
port( clk,rst : in std_logic;
t : in std_logic_vector(4 downto 0);
s : out std_logic_vector(1 downto 0);
a,b : in std_logic_vector(7 downto 0);
quotient,remainder : out std_logic_vector(7 downto 0));
end component;
signal t : std_logic_vector(4 downto 0);
signal s : std_logic_vector(1 downto 0);
begin
cp : controlPath
port
map(clk,rst,input_ready,divider_ready,output_ready,output_accepted,t,s);
dp : dataPath
port map(clk,rst,t,s,dividend,divisor,quotient,remainder);
end structure;
----------------------------------------------------------------Divider components--------------------------------------------shiftCounter8-----------------------------------------------library ieee;
use ieee.std_logic_1164.all;
entity shiftCount8 is
port (A: in std_logic_vector(3 downto 0);
B: out std_logic_vector(3 downto 0));
end entity shiftCount8;
architecture Serial of shiftCount8 is
begin
process(A)
variable borrow: std_logic;
begin
borrow := '1';
for I in 0 to 3 loop
B(I) <= A(I) xor borrow;
borrow := borrow and (not A(I));
end loop;
end process;
end Serial;
---------------------------------------------------------------- left shifter 8 Bit ---------------------------------------library ieee;
use ieee.std_logic_1164.all;
entity lshift8 is
port ( A : in std_logic_vector(7 downto 0);
B : out std_logic_vector(7 downto 0));
end entity;
architecture structure of lshift8 is
begin
B(7 downto 1) <= A(6 downto 0);
B(0) <= '0';
end architecture;
----------------------------------------------------------------8 Bit Sub--------------------------------------------------library ieee;
use ieee.std_logic_1164.all;
entity sub8bit is
port( A,B : in std_logic_vector(7 downto 0);
sub : out std_logic_vector(7 downto 0));
end entity;
architecture serial of sub8bit is
signal bbar : std_logic_vector(7 downto 0);
begin
bbar <= not(B);
process(A,bbar)
variable carry: std_logic;
begin
carry := '1';
for I in 0 to 7 loop
sub(I) <= (A(I) xor bbar(I)) xor carry;
carry := (carry and (A(I) or bbar(I))) or (A(I) and bbar(I));
end loop;
end process;
end architecture;
--Comparator-------------------------------------------------library ieee;
use ieee.std_logic_1164.all;
entity cmp8 is
port (A,B : in std_logic_vector(7 downto 0);
g,e,l: out std_logic);
end entity;
architecture structure of cmp8 is
component compBlock is
port(gp,ep,lp : in std_logic;
ak,bk : in std_logic;
g,e,l : out std_logic);
end component;
signal gTmp,eTmp,lTmp : std_logic_vector(6 downto 0);
begin
cmp7 : compBlock port
map('0','1','0',A(7),B(7),gTmp(0),eTmp(0),lTmp(0));
cmp6 : compBlock port
map(gTmp(0),eTmp(0),lTmp(0),A(6),B(6),gTmp(1),eTmp(1),lTmp(1));
cmp5 : compBlock port
map(gTmp(1),eTmp(1),lTmp(1),A(5),B(5),gTmp(2),eTmp(2),lTmp(2));
cmp4 : compBlock port
map(gTmp(2),eTmp(2),lTmp(2),A(4),B(4),gTmp(3),eTmp(3),lTmp(3));
cmp3 : compBlock port
map(gTmp(3),eTmp(3),lTmp(3),A(3),B(3),gTmp(4),eTmp(4),lTmp(4));
cmp2 : compBlock port
map(gTmp(4),eTmp(4),lTmp(4),A(2),B(2),gTmp(5),eTmp(5),lTmp(5));
cmp1 : compBlock port
map(gTmp(5),eTmp(5),lTmp(5),A(1),B(1),gTmp(6),eTmp(6),lTmp(6));
cmp0 : compBlock port map(gTmp(6),eTmp(6),lTmp(6),A(0),B(0),g,e,l);
end architecture;
---------------------------------------------------------------- Register---------------------------------------------------library ieee;
use ieee.std_logic_1164.all;
entity DataRegister is
generic (data_width:integer);
port (Din: in std_logic_vector(data_width-1 downto 0);
Dout: out std_logic_vector(data_width-1 downto 0);
enable,clk: in std_logic);
end entity;
architecture Behave of DataRegister is
begin
process(clk)
begin
if(clk'event and (clk = '1')) then
if(enable = '1') then
Dout <= Din;
end if;
end if;
end process;
end Behave;
---------------------------------------------------------------