MUL16.V
上传用户:saul_905
上传日期:2013-11-27
资源大小:184k
文件大小:1k
源码类别:

VHDL/FPGA/Verilog

开发平台:

Visual C++

  1. module mult16(clk,resetb,start,done,ain,bin,yout);
  2. parameter N=16;
  3. input             clk;
  4. input             resetb;
  5. input             start;
  6. input  [N-1:0]    ain;
  7. input  [N-1:0]    bin;
  8. output [2*N-1:0]  yout;
  9. output            done;
  10. reg    [2*N-1:0]  a;
  11. reg    [N-1:0]    b;
  12. reg    [2*N-1:0]  yout;
  13. reg               done;
  14. always@(posedge clk or negedge resetb)
  15.       begin
  16.          if(~resetb)
  17.             begin
  18.               a<=0;
  19.               b<=0;
  20.               yout<=0;
  21.               done<=1'b1;
  22.              end
  23.              
  24.          else
  25.              begin
  26.                 if(start)
  27.                      begin
  28.                        a<=ain;
  29.                        b<=bin;
  30.                        yout<=0;
  31.                        done<=0;
  32.                      end
  33.                   
  34.                 else
  35.                      begin
  36.                        if(~done)
  37.                            begin
  38.                            if(b!=0)
  39.                              begin
  40.                              if(b[0])yout<=yout+a;
  41.                                 b<=b>>1;
  42.                                 a<=a<<1;
  43.                              end
  44.                         
  45.                            else
  46.                            done<=1'b1;
  47.                            end
  48.                      end
  49.              end
  50.        end
  51. endmodule
  52.                 
  53.                         
  54.                 
  55.