0

我已经为组合乘法和顺序乘法编写了两个不同的 Verilog 片段,我将它们发布在下面。当我模拟任何一个乘法时,表示的乘数mult_A和被乘数表示mult_B它们的位串值,但表示的结果乘积R显示所有 X。帮助显示代码乘法结果R将不胜感激。

组合

module com_multiplication(mult_A, mult_B, R);
    input [15:0] mult_A, mult_B;
    output R;

    reg [31:0] R;

    integer k;

    always@(mult_A, mult_B)
    begin
    R = 0;
    for(k = 0; k < 16; k = k + 1)
        if(mult_A[k] == 1'b1) R = R + (mult_B << 1);
    end
 endmodule

串行

module ser_multiplication(mult_A, mult_B, clk, start, R, finish);
    input [15:0] mult_A, mult_B;
    input clk, start;
    output R, finish;

    reg [31:0] R;
    reg [15:0] mult_A_duplicate;
    reg [31:0] mult_B_duplicate;
    reg [4:0] p;
    wire finish = !p;

    initial p = 0;

    always@(posedge clk)
      if (finish && start) begin
        p = 16;
        R = 0;
        mult_B_duplicate = {16'd0, mult_B};
        mult_A_duplicate = mult_A;

      end else if (p) begin
         if (mult_A_duplicate[0] == 1'b1) R = R + mult_B_duplicate;
            mult_A_duplicate = mult_A_duplicate >> 1;
            mult_B_duplicate = mult_B_duplicate << 1;
            p = p - 1;
      end
endmodule

试验台

现在串行部分被注释掉了。

module multiplication_tb; 
  reg clk, start, finish; 
  reg [15:0] mult_A,  mult_B;
  reg [31:0] R; 

  com_multiplication U0 (  
  .mult_A                   (mult_A),
  .mult_B                   (mult_B),
  .R                        (R) 
  ); 

  /*ser_multiplication U1 (  
  .clk                      (clk),
  .start                        (start),
  .finish                   (finish),
  .mult_A                   (mult_A),
  .mult_B                   (mult_B),
  .R                        (R)
  ); */


  initial 
  begin 
  $display("time\t clk start finish");  
  $monitor ("%g\t %b %b %b %b %b %b", $time, clk, start, finish, mult_A, 
mult_B, R);
    #100     clk = 0; 
    mult_A =0;
    mult_B = 0;
    #10 mult_A = 2;
    mult_B = 3;
   #20 mult_B=2;

   #10 mult_B=5;
   #100 $finish;
 end 

 always 
 #5 clk = !clk; 

endmodule 
4

1 回答 1

1

我只是看了你的代码,但看起来你的时钟没有切换。制作永远切换时钟的简单方法是:

initial
begin
   clk = 1'b0;
   forever
     #50 clk = ~clk;
end
于 2018-03-02T09:22:52.563 回答