// Exercise B6: an 8-bit shift register, serial input, parallel output.
//
// Generic version that matches schematic 1: eight D flip-flops in a chain,
// with a common clock and an asynchronous reset, not tied to any chip.
// Synthesizable.

module shift_register
(
    input  logic       clk,
    input  logic       rst,  // 1 = all bits go to 0 at once, like RESET A and B of the 4015
    input  logic       d,    // The serial input

    output logic [7:0] q     // q [0] is the newest bit, q [7] the oldest
);

    // Every clock the bits move one place up and d comes in at the bottom

    always_ff @ (posedge clk or posedge rst)
        if (rst)
            q <= '0;
        else
            q <= { q [6:0], d };

endmodule
