G6.2.1 Universal Shift Register

MediumImplementIcarus Verilog + Yosys · serverReview the topic

Build a 6-bit shift register that clears, loads, shifts either way with its own serial input, or holds, by a fixed priority.

Hardware context: A 6-bit display scroll register with separate controls, and a receiver and transmitter for 8-bit sensor readings sent LSB first. Build a universal shift register with a fixed control priority.

A display driver needs a 6-bit register that can load a pattern, scroll it either way, or hold it. The controls come from different blocks, so more than one can be 1 in the same cycle.

This is an Implement problem. Complete ushift6. The priority is fixed: clear, then load, then shift, else hold. The check runs eight edges per case and reads q after each.

Signals in the Timeline

SignalWidthRole
script96input of each check
Full specification
The module (keep the name and the ports)
module ushift6 (
  input  logic       clk,
  input  logic       clr,     // synchronous clear
  input  logic       load,    // load d in parallel
  input  logic       shift,   // shift one place
  input  logic       dir,     // 0: shift right (toward q[0]); 1: shift left (toward q[5])
  input  logic       sr_in,   // enters q[5] on a right shift
  input  logic       sl_in,   // enters q[0] on a left shift
  input  logic [5:0] d,
  output logic [5:0] q
);
  ...
endmodule
At a rising edgeq becomes
clr = 1000000
otherwise, load = 1d
otherwise, shift = 1 and dir = 0 (right){sr_in, q[5:1]}: every bit moves toward q[0], sr_in enters q[5]
otherwise, shift = 1 and dir = 1 (left){q[4:0], sl_in}: every bit moves toward q[5], sl_in enters q[0]
otherwiseq (hold)

Each case starts with a clear edge. The result shows q after each of eight edges.

Examples

Example 1

Load, Then Shift Right Three Times
Input
load 101101; right sr_in=0; right sr_in=1; right sr_in=0; hold; hold; right sr_in=1; hold
Output
q_after_edge1 = 'b101101, q_after_edge2 = 'b010110, q_after_edge3 = 'b101011, q_after_edge4 = 'b010101, q_after_edge5 = 'b010101, q_after_edge6 = 'b010101, q_after_edge7 = 'b101010, q_after_edge8 = 'b101010

After the load q is 101101. Each right shift moves every bit toward q[0] and brings sr_in in at q[5]. Hold steps keep q.

Example 2

Load, Then Shift Left with sl_in = 1
Input
load 000011; left sl_in=1; left sl_in=1; left sl_in=0; hold; left sl_in=1; hold; left sl_in=0
Output
q_after_edge1 = 'b000011, q_after_edge2 = 'b000111, q_after_edge3 = 'b001111, q_after_edge4 = 'b011110, q_after_edge5 = 'b011110, q_after_edge6 = 'b111101, q_after_edge7 = 'b111101, q_after_edge8 = 'b111010

Each left shift moves every bit toward q[5] and brings sl_in in at q[0]. sr_in does not matter on a left shift.

Example 3

Priority: Clear, Then Load, Then Shift
Input
load 111000; load 010101 (+shift); clr+load; load 100001; right sr_in=1; clr+shift; right sr_in=1; hold
Output
q_after_edge1 = 'b111000, q_after_edge2 = 'b010101, q_after_edge3 = 'b000000, q_after_edge4 = 'b100001, q_after_edge5 = 'b110000, q_after_edge6 = 'b000000, q_after_edge7 = 'b100000, q_after_edge8 = 'b100000

Load beats shift at edge 2, and clear beats load at edge 3. At edge 6 clear beats a shift.

Constraints and Contract

  • All inputs are known 0/1 values and change only between edges.
  • Keep the module name and the ports. The design must synthesize with no latches.

Hints

Hint 1

One if / else if chain in the order of the priority table makes the priority certain.

Hint 2

A shift is one concatenation. For a right shift the new bit goes on the left of the concatenation.

Hint 3

Hold needs no code in a clocked block: if no branch assigns q, it keeps its value.

What the grader checks: Three directed and twelve seeded scripts of eight edges, with several controls at 1 in the same cycle. q is compared with a JavaScript model after every edge. Synthesis must report no latches.

The submitted design must synthesize with 0 latches and no combinational loop. Counts come from the pinned open-source synthesis flow. They are proxies for logic size and depth, not physical area or timing.

15 checks on Icarus Verilog + Yosys · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 3 steps and the final capstone

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Load, Then Shift Right Three Times

Input
load 101101; right sr_in=0; right sr_in=1; right sr_in=0; hold; hold; right sr_in=1; hold
Expected output
q_after_edge1 = 'b101101, q_after_edge2 = 'b010110, q_after_edge3 = 'b101011, q_after_edge4 = 'b010101, q_after_edge5 = 'b010101, q_after_edge6 = 'b010101, q_after_edge7 = 'b101010, q_after_edge8 = 'b101010

After the load q is 101101. Each right shift moves every bit toward q[0] and brings sr_in in at q[5]. Hold steps keep q.

Run samples executes all 3 public checks. Check all tests runs 15 checks on the server.

Icarus Verilog + Yosys · server