firmwareMIT

Shift register in Verilog

breadboardhub/shift-register-in-verilog
verilogtestbenchshiftregister
ShareXLinkedInFacebookRedditWhatsApp
B
Mike M
v1.0.0 · UpdatedNov 24, 2026 ·0 downloads ·0 forks
Verilog, with a testOpen in the chip playground
// An 8-bit shift register. On each rising clock edge every bit moves
// one place left and din enters at bit 0. rst clears it.
module shift8 (
  input  wire       clk,
  input  wire       rst,
  input  wire       din,
  output reg  [7:0] q
);
  always @(posedge clk) begin
    if (rst)
      q <= 8'd0;
    else
      q <= {q[6:0], din};
  end
endmodule
Description

Bits march left one place per clock. It comes with a test that builds with Yosys and runs in the browser. Clear it first: rst to 1, Step clock, rst to 0. Then set din to 1 for one step and back to 0, and watch the 1 move along q.

Cite this design
@design{breadboardhub/shift-register-in-verilog,
  title = {Shift register in Verilog},
  author = {breadboardhub},
  url = {https://www.breadboardhub.com/breadboardhub/shift-register-in-verilog},
  version = {1.0.0}
}