Part of Curriculum: Sequential RTL Design (Module 6: Shift Registers (SISO, SIPO, PISO))
View Full Roadmap →
Level 2 Medium ★ Flagship #18 25 pts ✓ Solved

4-Bit Shift Register — Data Shifting

Sequential Logic · sequential, fsm, counters, medium, shift-registers

Implement a 4-bit serial-in parallel-out (SIPO) shift register. On each clock edge, data shifts left: q[3]<=q[2], q[2]<=q[1], q[1]<=q[0], q[0]<=din.

Write a synthesizable Verilog module named top_module matching the ports below exactly.
📐 Circuit Schematic Diagram
FF0FF1FF2FF3dinq[3:0]>clk
⚡ Timing & Synthesizability Constraints

Timing Contract: Data shifts by one position on each `posedge clk`. Requires 4 clock cycles to fully load 4 serial bits.

RTL Constraints: Non-blocking assignments to model pipeline flop stages accurately.

Objective: Understand sequential bit shifting, concatenation operators (`{}`), and serial-to-parallel conversion.

Prerequisites: Flip-flop cascades, bit concatenation syntax.
NameDirWidthDescription
clkinput1Master clock
areset_ninput1Active-low asynchronous reset
dininput1Serial data input
qoutput44-bit parallel register output
Expected Waveform (Golden Timing Contract)
💡 Need Guidance? Progressive Hints (3 Levels)
Hint 1: Conceptual Direction & Hardware Primitives
Use concatenation: `{q[2:0], din}` shifts all bits left by 1 and inserts `din` into the LSB (`q[0]`).
Hint 2: Implementation Architecture & Approach
Non-blocking assignments (`<=`) ensure all 4 flip-flops sample their predecessors simultaneously without race conditions.
Hint 3: Edge Cases, Timing & Verilog Syntax
Write `q <= {q[2:0], din};`.
🔒 Reveal Verified Reference RTL Solution (Click to expand)
⚠️ Self-Discovery Warning: Try solving and simulating first! Viewing the verified reference implementation will bypass the real debugging experience.
Verified Synthesizable RTL
module top_module(
  input        clk,
  input        areset_n,
  input        din,
  output reg [3:0] q
);
  always @(posedge clk or negedge areset_n) begin
    if (!areset_n)
      q <= 4'b0000;
    else
      q <= {q[2:0], din};
  end
endmodule
Verilog-2001 / SV Saved
Font: |
// Click Run Tests (or press Ctrl+Enter) to compile your RTL and simulate against hidden testbenches.
Simulation Timing Diagram (VCD Waveform)
100%
No simulation waveform yet. Run tests to simulate and generate VCD traces.
No compilation run yet. Syntax warnings and elaboration messages will appear here.
No simulation output yet. Raw stdout from vvp will appear here.

RTL Problems / Level 2 · Sequential Logic

What You Will Learn

By solving 4-Bit Shift Register — Data Shifting, you will acquire core industry skills:

  • Synthesizable hardware modeling in standard Verilog-2001 / SystemVerilog.
  • Correct handling of interface port contracts, edge-triggered clocks, and active-low/high resets.
  • Simulation waveform interpretation and debugging using timing diagrams (VCD traces).
  • Architectural avoidance of timing violations, glitching hazards, and synthesis warnings.

Problem Statement & Requirements

Implement a 4-bit serial-in parallel-out (SIPO) shift register. On each clock edge, data shifts left: q[3]<=q[2], q[2]<=q[1], q[1]<=q[0], q[0]<=din.

Hardware design teams at leading semiconductor firms evaluate these exact port contracts, race-condition assertions, and corner cases during technical design reviews and ASIC engineer interviews.

Objective: Understand sequential bit shifting, concatenation operators (`{}`), and serial-to-parallel conversion.

Prerequisites: Flip-flop cascades, bit concatenation syntax.

Port List & Interface Timing

The hidden testbench instantiates top_module. Module port names and bit-widths must match the interface contract exactly:

NameDirWidthDescription
clkinput1Master clock
areset_ninput1Active-low asynchronous reset
dininput1Serial data input
qoutput44-bit parallel register output

Timing Constraints & Synthesizable RTL Rules

⚡ Synthesizable Implementation Guidelines

Timing Contract: Data shifts by one position on each `posedge clk`. Requires 4 clock cycles to fully load 4 serial bits.

Synthesis Constraints: Non-blocking assignments to model pipeline flop stages accurately.

Architectural Deep Dive & Implementation Walkthrough

A shift register connects the output of one flip-flop directly to the input of the next. On every clock tick, bits move along the pipeline chain. In SPI, UART, and I2C controllers, shift registers convert between bit-serial physical wires and byte-parallel processor registers.

Common RTL Designer Pitfalls

⚠️ Common Mistakes to Avoid

['Using blocking assignments (`=`), causing all flip-flops to update in sequence in a single simulation delta cycle, corrupting the pipeline.', 'Shifting in the wrong direction (confusing `{din, q[3:1]}` right shift with `{q[2:0], din}` left shift).']

Silicon & Hardware Engineering Notes

🛠️ ASIC vs FPGA Hardware Considerations

Modern FPGAs (AMD/Xilinx) can configure a single LUT as a 32-bit shift register (SRL32), implementing deep shift registers with zero flip-flop overhead.

Starter RTL Code

module top_module(
  input        clk,
  input        areset_n,
  input        din,
  output reg [3:0] q
);

  // 4-bit left shift register

endmodule

Verified Reference Solution

🔒 Reveal Verified Reference RTL Solution
module top_module(
  input        clk,
  input        areset_n,
  input        din,
  output reg [3:0] q
);
  always @(posedge clk or negedge areset_n) begin
    if (!areset_n)
      q <= 4'b0000;
    else
      q <= {q[2:0], din};
  end
endmodule

Related RTL Problems in Level 2

Frequently Asked Questions

What does 4-Bit Shift Register — Data Shifting require?

Implement a 4-bit serial-in parallel-out (SIPO) shift register. On each clock edge, data shifts left: q[3]<=q[2], q[2]<=q[1], q[1]<=q[0], q[0]<=din. Implement it as Verilog module top_module matching the listed ports.

Is this design combinational or sequential?

Tags: sequential, fsm, counters, medium, shift-registers. If a clock signal is present in the port table, implement it as sequential logic; otherwise, use continuous assignments or combinational blocks.

How is my solution graded?

A hidden SystemVerilog testbench simulates your module in the cloud judge. You pass when all directed corner cases match the golden model and the VCD timing waveform matches the contract.

How does this challenge help with semiconductor interviews?

Technical interviewers at NVIDIA, Qualcomm, Apple, and Intel routinely ask candidates to code, debug, and explain the timing waveforms of 4-Bit Shift Register — Data Shifting to assess real-world synthesizability and race-condition awareness.