移位寄存器Verilog HDL输出给出xxxxxxx

移位寄存器Verilog HDL输出给出xxxxxxx,verilog,hdl,shift-register,Verilog,Hdl,Shift Register,我正在尝试用Verilog HDL制作一个64位移位寄存器。当我在测试台上尝试代码时,我只得到xxxxxx作为输出,直到所有的位都被移位。我不知道是什么问题。 以下是我的测试台代码和结果: module ShiftRegister (shift_out, clk, shift_in); //module ports parameter n = 64; //Parameter n declared to store 64 input [n-1:0] shift_in; //64-bit i

我正在尝试用Verilog HDL制作一个64位移位寄存器。当我在测试台上尝试代码时,我只得到xxxxxx作为输出,直到所有的位都被移位。我不知道是什么问题。 以下是我的测试台代码和结果:

module ShiftRegister (shift_out, clk, shift_in); //module ports
  parameter n = 64; //Parameter n declared to store 64
  input [n-1:0] shift_in; //64-bit input shift_in
  input clk; //Input clock
  output [n-1:0] shift_out; //64-bit output shift_out
  reg [n-1:0] ff; //64-bit flipflop
  assign shift_out = ff [n-1:0]; //give the output of the 64th bit
  //The operation of verilog: 
   always @ (posedge clk) //Always at the rising edge of the clock
   begin
     ff <= ff << 1;  //Shift bits to the left by 1
     ff[0] <= shift_in; //Take the input bits and give it to the first flipflop
     end
endmodule //ShiftRegister module

///Testbench\\\ 
module ShiftRegister_tb; //Module shiftRegister_tb
   parameter n = 64; //Parameter n declared to store 64
   reg [n-1:0] shift_in; //64-bit register input shift_in
   reg clk, rst; //register clock
   wire [n-1:0] shift_out; //64-bit wire output shift_out
   ShiftRegister DUT(shift_out, clk, shift_in); //Calling the module
  initial
    begin
    clk = 0; //clock = 0 initally
    shift_in = 64'd34645767785344; //Random decimal number to test the code 
    #100;
   end
 always #50 clk =~clk; //invert the clock input after 50ps
endmodule //ShiftRegister testbench
模块移位寄存器(移出、锁定、移入)//模块端口
参数n=64//参数n声明为存储64
输入[n-1:0]档位输入//64位输入移位输入
输入时钟//输入时钟
输出[n-1:0]移出//64位输出移位输出
注册号[n-1:0]ff//64位触发器
分配shift_out=ff[n-1:0]//给出第64位的输出
//verilog的操作:
始终@(posedge clk)//始终处于时钟的上升沿
开始

ff您将
ff
声明为
reg
,而
reg
的默认值为
x
。在时钟的第一个posedge之前,
ff
的所有64位都是
x
(未知)。在时钟的第一个posedge之后,
ff[0]
变为0,因为[0]
中的
shift\u为0。以此类推,直到达到64个时钟,所有
ff
位都是0<代码>移出
紧跟在
ff
之后

通常,您的设计也会有重置信号。如果有,可以在开始时断言reset,并在reset期间将
ff
赋值为0。以下是重置后的情况:

module ShiftRegister (shift_out, clk, shift_in, rst); //module ports
    parameter n = 64; //Parameter n declared to store 64
    input rst;
    input [n-1:0] shift_in; //64-bit input shift_in
    input clk; //Input clock
    output [n-1:0] shift_out; //64-bit output shift_out
    reg [n-1:0] ff; //64-bit flipflop
    assign shift_out = ff [n-1:0]; //give the output of the 64th bit

    always @ (posedge clk or posedge rst) //Always at the rising edge of the clock
    begin
        if (rst) begin
            ff <= 0;
        end else begin
            ff <= ff << 1;  //Shift bits to the left by 1
            ff[0] <= shift_in; //Take the input bits and give it to the first flipflop
        end
    end
endmodule

module ShiftRegister_tb; //Module shiftRegister_tb
    parameter n = 64; //Parameter n declared to store 64
    reg [n-1:0] shift_in; //64-bit register input shift_in
    reg clk, rst; //register clock
    wire [n-1:0] shift_out; //64-bit wire output shift_out
    ShiftRegister DUT(shift_out, clk, shift_in,rst); //Calling the module
    initial
    begin
        clk = 0; //clock = 0 initally
        rst = 1;
        shift_in = 64'd34645767785344; //Random decimal number to test the code 
        #100;
        rst = 0;
        #50_000 $finish;
    end
    always #50 clk =~clk; //invert the clock input after 50ps
endmodule
模块移位寄存器(移出、clk、移入、rst)//模块端口
参数n=64//参数n声明为存储64
输入rst;
输入[n-1:0]档位输入//64位输入移位输入
输入时钟//输入时钟
输出[n-1:0]移出//64位输出移位输出
注册号[n-1:0]ff//64位触发器
分配shift_out=ff[n-1:0]//给出第64位的输出
始终@(posedge clk或posedge rst)//始终位于时钟的上升沿
开始
如果(rst)开始
ff
ff[0]