Serial In Serial Out Shift Register

 module SISO(clk,rst,d,q);

    input clk,rst,d;

    output q;

    reg [3:0] temp;


    always@(posedge clk or negedge rst)

    begin

        if(rst == 1'b1)

            temp <= 4'b0;

        else

            begin

                temp[3] <= d;

                temp     <= temp >>1;

            end

                assign q = temp[0];

endmodule


Testbench

module SISO_tb;

    reg t_clk, t_rst, t_d;

    wire t_q;

    SISO SISO_tb(.clk(t_clk),

                              .rst (t_rst),

                              .d   (t_d),

                               .q  (t_q)

                               );

    initial

        begin

            t_clk = 1'b0;

            t_rst = 1'b0;

            t_d   = 1'b0;

        end

        always #10 t_clk = ~t_clk;

        always #15 t_rst  = ~t_rst;

        always #20 t_d   = ~t_d;

        initial

            begin

                 $monitor("%t,t_d=%b,t_q=%b",$time,t_d,t_q);

            end

endmodule

Comments

Popular posts from this blog

2X1 Multiplexer