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

VHDL/FPGA/Verilog

开发平台:

Visual C++

  1. `timescale 1ns/1ps
  2. module mult_piped_8x8_2sC(a,b,clk,reset,y);
  3. input [7:0]a,b;
  4. input clk,reset;
  5. output [15:0] y;
  6. reg[7:0] aR [8:0];
  7. reg[7:0] bR [8:0];
  8. reg[15:0]yR [8:0];
  9. always@(posedge clk)
  10.         begin
  11.           aR[7]  =  aR[6];
  12.           bR[7]  =  bR[6];
  13.           yR[7]  =  yR[6];
  14.           aR[6]  =  aR[5];
  15.           bR[6]  =  bR[5];
  16.           yR[6]  =  yR[5];
  17.           aR[5]  =  aR[4];
  18.           bR[5]  =  bR[4];
  19.           yR[5]  =  yR[4];
  20.           aR[4]  =  aR[3];
  21.           bR[4]  =  bR[3];
  22.           yR[4]  =  yR[3];
  23.           aR[3]  =  aR[2];
  24.           bR[3]  =  bR[2];
  25.           yR[3]  =  yR[2];
  26.           aR[2]  =  aR[1];
  27.           bR[2]  =  bR[1];
  28.           yR[2]  =  yR[1];
  29.           aR[1]  =  aR[0];
  30.           bR[1]  =  bR[0];
  31.           yR[1]  =  yR[0];
  32.           //muliply result  (a*b) appears after +clk
  33.           
  34.           aR[0]  =a;
  35.           bR[0]  =b;
  36.           yR[0]  =multiply_8x8_2sC (aR[0],bR[0]);
  37.           
  38.           end
  39.           
  40.           
  41.           function[15:0] multiply_8x8_2sC;
  42.           input [7:0] a,b;
  43.           reg   [7:0] a_mag,b_mag;
  44.           reg   [14:0] Y_mag;
  45.           reg   [14:0] Y_neg;
  46.           
  47.           begin
  48.                case (a[7])
  49.                     0:a_mag  =   a[6:0];
  50.                     1:a_mag  =128-a[6:0];
  51.                endcase
  52.                
  53.                case  (b[7])
  54.                     0:b_mag  =  b[6:0];
  55.                     1:b_mag  =128-b[6:0];
  56.                 endcase
  57.                 
  58.                 
  59.                 
  60.                 Y_mag=a_mag*b_mag;
  61.                 if((a[7]^b[7])&(Y_mag!=0))
  62.                       begin
  63.                       Y_neg=32768-Y_mag[13:0];
  64.                       multiply_8x8_2sC={1'b1,Y_neg};
  65.                       end
  66.                  
  67.                  else
  68.                       multiply_8x8_2sC=Y_mag;
  69.             end
  70.             endfunction
  71.             
  72.             
  73.             assign  y=yR[7];
  74.           endmodule
  75.           
  76.                      
  77.          
  78.