Sequential For Loop Shift Register
Digital signal processing pipelines and delay lines frequently require parameterized shift registers to align data streams across multiple clock cycles. The module acts as a configurable delay line. When enabled, it captures the input data and shifts existing data down a chain of registers. The output exposes the final register in the chain, effectively delaying the input by a parameterized number of clock cycles.
- Clock edge:
posedge clk - Reset type: Asynchronous active-low
- Reset polarity: When
rst_nis 0, all internal shift register stages andd_outclear to 0. - Priority rules: Reset takes priority over all other operations. When
rst_nis 1, theensignal dictates operation. - Operation: On the clock edge, if
enis 1,d_inis loaded into the first stage, and stageimoves to stagei+1. Ifenis 0, all stages hold their current values. - Output: The output
d_outis continuously driven by the final stage of the shift register (DEPTH-1).
Worked Trace (DEPTH=4, WIDTH=8): Cycle 1: rst_n=0 → stages=[00, 00, 00, 00], d_out=00 Cycle 2: rst_n=1, en=1, d_in=AA → stages=[AA, 00, 00, 00], d_out=00 Cycle 3: en=1, d_in=BB → stages=[BB, AA, 00, 00], d_out=00 Cycle 4: en=1, d_in=CC → stages=[CC, BB, AA, 00], d_out=00 Cycle 5: en=1, d_in=DD → stages=[DD, CC, BB, AA], d_out=AA Cycle 6: en=0, d_in=EE → stages=[DD, CC, BB, AA], d_out=AA (hold)
{ "signal": [
{ "name": "clk", "wave": "p......" },
{ "name": "rst_n", "wave": "01....." },
{ "name": "en", "wave": "01...0." },
{ "name": "d_in", "wave": "x======", "data": ["AA", "BB", "CC", "DD", "EE"] },
{},
{ "name": "d_out", "wave": "=======", "data": ["00", "00", "00", "00", "00", "AA", "AA"] }
], "head": { "text": "Cycle-by-cycle shift operation with DEPTH=4." } }| Parameter | Default | Description | |-----------|---------|-------------| | DEPTH | 8 | Number of stages in the shift register | | WIDTH | 8 | Bit width of the data path |
| Signal | Direction | Width | Description | |--------|-----------|-------|-------------| | clk | input | 1 | Positive-edge triggered clock | | rst_n| input | 1 | Asynchronous active-low reset | | en | input | 1 | Active-high shift enable | | d_in | input | WIDTH | Data input to the first stage | | d_out| output | WIDTH | Data output from the final stage |
Constraints
- The module must be parameterized with
DEPTHandWIDTHusing exactly those parameter names. - You must use a
forloop inside a clocked procedural block to define the shift register stages. - Output values must transition exactly on the clock edge, reflecting the updated internal state.
- All internal register stages must be explicitly cleared to 0 upon reset.
Topics
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.
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.