【文章內(nèi)容簡介】
cess(clk) 同步數(shù)據(jù)更新進程 begin if(clk=39。139。and clk39。event) then state=nextstate。 if load=39。139。 then dividend=39。039。amp。dividend_in。 end if。 if su=39。139。 then dividend(8 downto 4)=subout。 dividend(0)=39。139。 end if。 if sh=39。139。 then dividend=dividend(7 downto 0)amp。39。039。 end if。 end if。 end process update。 end Behavioral。 library IEEE。 use 。 use 。 use 。 entity divider is Port ( dividend_in : in std_logic_vector(7 downto 0)。 被除數(shù) divisor : in std_logic_vector(3 downto 0)。 除數(shù) st : in std_logic。 除法啟動控制信號 clk : in std_logic。 時鐘信號 quotient : out std_logic_vector(3 downto 0)。 商 remainder : out std_logic_vector(3 downto 0)。 余數(shù) overflow : out std_logic)。 溢出標志 end divider。 architecture Behavioral of divider is signal state,nextstate:integer range 0 to 5。 signal c,load,su,sh:std_logic。 signal subout:std_logic_vector(4 downto 0)。 signal dividend:std_logic_vector(8 downto 0)。 begin subout=dividend(8 downto 4)(39。039。amp。divisor)。 減法器 c=not subout(4)。 remainder=dividend(7 downto 4)。 分離出余數(shù) quotient=dividend(3 downto 0)。 分離出商 state_graph:process(state,st,c) 狀態(tài)控制器 begin load=39。039。overflow=39。039。sh=39。039。su=39。039。 case state is when 0= 狀態(tài) 0 :啟動除法運算 if(st=39。139。) then load=39。139。nextstate=1。 else nextstate=0。 end if。 when 1= 狀態(tài) 1 :溢出判斷 if(c=39。139。)then overflow=39。139。nextstate=0。 else sh=39。139。nextstate=2。 end if。 when 2|3|4= 狀態(tài) 4:實現(xiàn)除法運算 if(c=39。139。)then su=39。139。nextstate=state。 else sh=39。139。nextstate=state+1。 end if。 when 5= 狀態(tài) 5:結(jié)束運算過程,返回初始態(tài) if(c=39。139。) then su=39。139。 end if。 nextstate=0。 end case。 end process state_graph。 update:process(clk) 同步數(shù)據(jù)更新進程 begin if(clk=39。139。and clk39。event) then state=nextstate。 if load=39。139。 then dividend=39。039。amp。dividend_in。 end if。 if su=39。139。 then dividend(8 downto 4)=subo