基于verilog的除法器.doc_第1页
基于verilog的除法器.doc_第2页
基于verilog的除法器.doc_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

module divider(quotient,remainder,ready,error,word1,word2,start,clock,reset);parameter L_divn=8, L_divr=4, S_idle=0,S_adivr=1,S_adivn=2,S_div=3,S_err=4, L_state=3,L_cnt=4,Max_cnt=L_divn-L_divr;output L_divn-1:0 quotient,remainder;output ready,error;input L_divn-1:0 word1;/dividendinput L_divr-1:0 word2;/divisorinput start,clock,reset;/0,start,1,resetreg L_state-1:0 state,next_state;reg Load_words,Subtract,Shift_dividend,Shift_divisor;reg L_divn-1:0 quotient;reg L_divn:0 dividend;reg L_divr-1:0 divisor; reg L_cnt-1:0 num_Shift_dividend,num_Shift_divisor;reg L_divr:0 comparison;wire MSB_divr=divisorL_divr-1;wire ready=(state=S_idle)&reset);wire error=(state=S_err);wire Max=(num_Shift_dividend=Max_cnt+num_Shift_divisor);wire sign_bit=comparisonL_divr;assign remainder=(dividendL_divn-1:L_divn-L_divr)num_Shift_divisor;/always (state or dividend or divisor or MSB_divr) case(state) S_adivr: if(MSB_divr=0) comparison=dividendL_divn:L_divn-L_divr+1b1,(divisor1)+1b1; else comparison=dividendL_divn:L_divn-L_divr+1b1,divisorL_divr-1:0+1b1; default: comparison=dividendL_divn:L_divn-L_divr+1b1,divisorL_divr-1:0+1b1; endcasealways (posedge clock or negedge reset) if(!reset) state=S_idle; else state=next_state;always (state or word1 or word2 or start or comparison or sign_bit or Max) begin Load_words=0;Subtract=0;Shift_dividend=0;Shift_divisor=0; case(state) S_idle: case(!start) 0: next_state=S_idle; 1: if(word2=0) next_state=S_err; else if(word1) begin next_state=S_adivr;Load_words=1; end else next_state=S_idle; endcase S_adivr: case(MSB_divr) 0: if(sign_bit=0) begin next_state=S_adivr;Shift_divisor=1; end else if(sign_bit=1) next_state=S_adivn; 1: next_state=S_div; endcase S_adivn: case(Max,sign_bit) 2b00: next_state=S_div; 2b01: begin next_state=S_adivn;Shift_dividend=1; end 2b10: begin next_state=S_idle;Subtract=1; end 2b11: next_state=S_idle; endcase S_div: case(Max,sign_bit) 2b00: begin next_state=S_div;Subtract=1; end 2b01: next_state=S_adivn; 2b10: begin next_state=S_div;Subtract=1; end 2b11: begin next_state=S_div;Shift_dividend=1; end endcase default: next_state=S_err; endcase endalways (posedge clock or negedge reset)begin if(!reset) begin divisor=0; dividend=0; quotient=0; num_Shift_dividend=0; num_Shift_divisor=0; end else if(Load_words=1) begin dividend=word1; divisor=word2; quotient=0; num_Shift_dividend=0; num_Shift_divisor=0; end else if(Shift_divisor) begin divisor=divisor1; num_Shift_divisor=num_Shift_divisor+1; end else if(Shift_dividend) begin dividend=dividend1; quotient=quotient1; num_S

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论