一乐电子

一乐电子百科

 找回密码
 请使用微信账号登录和注册会员

QQ登录

只需一步,快速开始

快捷登录

手机号码,快捷登录

搜索
查看: 2645|回复: 0
收起左侧

verilog 除法方法

[复制链接]
发表于 2013-10-31 21:35 | 显示全部楼层 |阅读模式

module mul(reset,shang,yushu,error,chushu,beichu);

input reset;6 N% H8 j3 ~) v! z& j" \8 D0 A3 `
input[3:0] chushu;   

input[3:0] beichu;      

output[3:0] shang;         

output[3:0] yushu;     

output error;         

reg[7:0] shift_beichu;   

reg[3:0] chushu_a;         

reg[3:0] shang;            

reg[3:0] yushu;           

wire error=(chushu==4'b0);   

always @(chushu or beichu)   
( o+ r+ ?; @1 Ibegin
$ p; @) \! M8 y+ l( F8 r1 K& a   if(!reset||error)           

   begin                              
8 ]+ V* F0 B( S* M7 C* G   shang=4'b0;
- q7 R- [6 g  {/ s' h8 x   yushu=4'b0;/ S- ?/ l' g# S  r! z+ l
   chushu_a=4'b0;( i. r1 a1 z$ r8 o: [
   shift_beichu=4'b0;    ! A; G! u, \3 x3 [
   end4 K- p2 J7 K) ^2 V; C: W2 l
else if(chushu>beichu)      

   begin/ q: G9 `& j, I9 I
   shang=4'b0;' i2 |: b( C* P6 ]: p
   yushu=beichu;% t2 \6 n& F& k- U0 a6 H8 G: W
   end
. W% Q+ T- S; D+ e! T" V% o else if(chushu==4'b1)      

   begin, o! B1 o- e9 C, T
   shang=beichu;
  a: T9 ?4 x) T   yushu=4'b0;
: Y6 K. x* F. R* R   end) F* e4 s( H/ ?3 V1 X
else                           
' \* v" @) D7 }, U; G- G. [& x   begin
6 ~; C! O2 o9 R$ t! G# |5 n     shang=4'b0;
5 g3 h* ]! w! E" t   chushu_a=chushu;5 K7 p- W7 V  `8 Y. u
   shift_beichu=beichu;     

   shift_beichu=shift_beichu<<1;    0 j1 e# _) F) }$ u: L
   repeat(3)                     

     begin
- h. r& q  ]/ ?) B5 o6 M" L& b7 j   shang=shang<<1;      

   shift_beichu=shift_beichu<<1;

   if(chushu_a<=shift_beichu[7:4])

     begin/ s0 o/ _) u0 C8 I# ]1 B
   shift_beichu[7:4]=shift_beichu[7:4]-chushu_a;7 `1 C- ~  i3 E( u" |3 \4 @4 @
   shang=shang+1;  ( W) l# |& [, V+ f0 a. j/ ]/ z7 w
   end   

     end
# A6 K0 f& T9 c$ S* b% k3 u  yushu=shift_beichu[7:4;

  end. \9 Z( @, ]7 P3 a- o8 o2 V
end
, _. N0 F4 |8 u6 i  lendmodule

: K" j6 f1 K/ T7 c4 x% q% M

本版积分规则

QQ|一淘宝店|手机版|商店|电子DIY套件|一乐电子 ( 粤ICP备09076165号 ) 公安备案粤公网安备 44522102000183号

GMT+8, 2024-6-15 18:23 , Processed in 0.055656 second(s), 22 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表