CodiodeCodiode
Home
Problem Solving
Skill Tracks
My Assignments
Contests
Leaderboard
Community
Settings
Codiode/Problems/Sequential Logic

Four Stage Shift Register

EasyVerilog / SystemVerilogBuild

Data alignment across multiple clock domains or pipelined stages often requires delaying a control signal by a fixed number of cycles. In DSP and communication circuits, shift registers are heavily used to synchronize parallel data paths that have different processing latencies.

A four-stage shift register accepts a serial input stream and passes it through four cascaded flip-flops. The output of the module is the input signal delayed by exactly four clock cycles. If the input goes high in cycle 1, the output will go high in cycle 5.

The circuit uses a positive-edge triggered clock. An asynchronous active-low reset clears all internal stages and the output to 0 immediately when asserted. When reset is de-asserted, the shift register captures the input on each rising clock edge and shifts the data forward one stage.

Cycle 1: rst_n=0 → q=0 Cycle 2: rst_n=1, d=1 → q=0 (data enters stage 1) Cycle 3: rst_n=1, d=0 → q=0 (data enters stage 2) Cycle 4: rst_n=1, d=0 → q=0 (data enters stage 3) Cycle 5: rst_n=1, d=0 → q=1 (data enters stage 4, appears at output) Cycle 6: rst_n=1, d=0 → q=0 (data shifts out)

{ "signal": [
  { "name": "clk",   "wave": "p......" },
  { "name": "rst_n", "wave": "01....." },
  { "name": "d",     "wave": "010...." },
  {},
  { "name": "q",     "wave": "0....10" }
], "head": { "text": "Input d is delayed by four clock cycles before appearing at output q." } }

| Signal | Direction | Width | Description | |--------|-----------|-------|-------------| | clk | input | 1 | Positive-edge triggered clock | | rst_n| input | 1 | Asynchronous active-low reset; all outputs and internal stages go to 0 when asserted | | d | input | 1 | Serial data input | | q | output | 1 | Serial data output, delayed by four clock cycles; resets to 0 |

Constraints

  • Clock is positive-edge triggered.
  • Reset is asynchronous and active-low.
  • Output q must be registered.
  • You must declare and instantiate four distinct register variables (for example q0, q1, q2, q3) rather than a single 4-bit array to prove your understanding of concurrent assignments.

Topics

Shift RegisterFlip-FlopsNon-blocking Assignments

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against a real testbench — you get the waveform back, not a stored answer.

This problem is part of Codiode Pro. The statement above is free to read.

Sign in to solveSee what Pro unlocks

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Related problems

  • Basic D Flip FlopEasy
  • Recursive Generate Reduction TreeHard
  • Phase Aligned Clock Domain CrossingHard
  • Struct Array PipelineHard
  • T Flip Flop from D Flip Flop TemplateEasy
  • Read After Write Hazard DetectionEasy
  • Parameterized Interface with ModportsHard
  • Debug: Missing Edge in Sensitivity ListMedium

Browse all problems · Learning tracks