8x8乘数代码和测试平台无法正常工作(shift-add verilog)

时间:2018-04-19 15:01:36

标签: verilog

我是verilog的新手,我正在尝试使用shift-add方法制作一个8x8位乘法器。我似乎无法让我的代码工作,我不确定它是语法问题还是逻辑错误。我还附加了testbench文件,因为我不确定我是否正确地完成了100%。当我运行模拟时,它表示所有输入和输出都是z。更新:我已将实例添加到测试平台,但我仍然得到z输出和输入。

 `timescale 1ns / 1ps
  module lab6code(
    input [7:0] mp, mc,
    input start,
    output reg done,
    reg state,
    reg i, // i is the variable that gets used to check a specific bit in the mplier
    reg [15:0] x, //holder
    output reg [15:0] product,
    input clk);


initial
 begin
    state=0;
    i=0;
    x=0;
 end

always @(posedge clk)
begin
    case(state)
    0:
    begin
        if(start==1)
            begin
            x[15:0] <= 4'b0000;
            x[7:0] <= mc; //assign multiplicand to holder
            state <= 1;
            end
    end

    1, 3, 5, 7, 9, 11, 13, 15:
    begin
        if(x[i]==0) //checks specific place within mplier array, shifts and moves ahead 2 states
            begin
             x = x << 1; //shifts mcand holder
             state <= state+2; //moves ahead 2 states
             i <= i + 1; //updates i so in the next case the next bit in mplier will be looked at
            end
        else //adds mplier and mcand, moves ahead one state
            begin
             x[7:0] <= x + mp; //adds mplier to the mplier register
             i <= i + 1; //updates i
            end

    end

    2, 4, 6, 8, 10, 12, 14, 16: //shifts mcand and goes to next state
    begin
        x = x << 1; //shifts mcand holder
        state <= state + 1; // moves ahead one state
    end

    17:
        begin
        state <=0;
        done = 1;
        end
       endcase
product = x;

end   


endmodule

测试平台:

`timescale 1ns / 1ps

module lab6tb(
output product,
reg start    );

reg mp, mc;

lab6code lab6code_instance(
.mc(mc),
.mp(mp),
.product(product),
.start(start)
);


initial
begin 
start = 1;
mp = 7'b00001011;
mc = 7'b00001001;
end
endmodule

1 个答案:

答案 0 :(得分:0)

您没有驱动lab6code模块的所有输入,最重要的是您没有开车时钟。 clk信号保持打开状态,因此它将是x,并且基于其上升沿的事件都不会发生。 在您的测试平台中,您需要创建一个小的无限循环,这将切换该时钟并为您的模块带来一些生命。

类似的东西:

reg clk;

initial
  clk = 1'b0;

always
begin
  #10
  clk = ~clk;
end

#10是时钟周期的一半。