Altera_Forum
Honored Contributor
17 years agoneed help for my project
below is given restoring method code and its algo(its link)
there is no error in the programme but output is not comming right please any one can give me hint why it is not coming right library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity dev1 is port(a,b: in std_logic_vector(3 downto 0):="0000"; quo : inout std_logic_vector(3 downto 0):="0000"; rem1: inout std_logic_vector(4 downto 0):="00000"); end dev1; architecture dev1 of dev1 is begin process(a,b) variable false:boolean; begin rem1<="00000"; quo <= a; if(a="0000" and b="0000") then assert false report"intermedite result" severity error; quo <= "XXXX"; rem1 <= "XXXXX"; elsif( b="0000") then assert false report "infinity" severity error; quo<="XXXX"; rem1<="XXXXX"; else for k in 3 downto 0 loop rem1<=rem1(3 downto 0) & quo(3); --shifting of rem1 and quo together by 1 means quo<=quo(2 downto 0) & '0'; -- in lsb of rem1 putting msb of quo and lsb of quoputting 0 rem1 <= rem1 - b; if(rem1(4) = '0') then --if rem1 is +ive means msb of quo is zero quo(0)<='1'; -- make lsb of quo one else rem1 <= rem1 + b; --if rem is negative means msb of quo is 1 -- restore the remainder end if; end loop; end if; end process; end; ALGORITHM(restoring method) Step 1: Take dividend & divisor as input. Step 2: Initialize remainder to zero & quotient to dividend. Step 3: If b is zero then display invalid divisor. Step 4: Else shift remainder & quotient to 1 bit left. Step 5: Then check if remainder is negative then subtract divisor from remainder. Else add divisor to remainder. Step 6: If remainder is negative then make LSB of quotient 0 . Else make LSB of quotient 1. Step 7: Repeat steps 4 to 6 n times where n is the number of bits in dividend. Step 8: If remainder is negative then restore it i.e add divisor to it. Step 9: Display remainder and quotient.