Storing a whole word, moving bits along a chain, serial and parallel conversion, and generating pseudo-random bits.
Storing a word
A register is a row of D flip-flops sharing one clock, storing one bit each. Eight of them hold a byte. Almost every data path is registers with logic between them: on each clock edge, the results of the logic land in the next register.
A plain flip-flop loads on every edge, but usually a register should only load when told to. A load enable adds a MUX in front of each D: when enable is 1 it takes new data, and when it's 0 it reloads its own output.
> Loading the circuit…
A 4-bit register with load enable. Change data freely: stored only changes at a clock edge while en is on.
Set data to 5, turn on en, and press Clock edge. It stores 5.
Turn en off, set data to 9, and clock again. It keeps 5.
Shift registers
Connect each flip-flop's output to the next one's input, and on every clock edge the bits all move along by one place. That's a shift register.
> Loading the animation…
Type
In
Out
Used for
SISO
Serial
Serial
Delaying a bit stream
SIPO
Serial
Parallel
Receiving: a serial line into a word
PISO
Parallel
Serial
Transmitting: a word onto a serial line
PIPO
Parallel
Parallel
An ordinary register
A universal shift register does all of this, choosing with mode inputs what each flip-flop's input MUX selects. The classic part is the 74194.
s1 s0
Action
0 0
Hold
0 1
Shift right
1 0
Shift left
1 1
Parallel load
> Loading the circuit…
A 4-bit shift register. With dir off, bits move towards bit 0, and si enters at the top. With dir on, they go the other way. The display is in hex.
Turn on si and clock four times: F appears, filling from the top: 8, C, E, F.
Set data to 5 and turn on load, clock once, then turn load off and clock again. 0101 shifts to 0010, which is the same as dividing by 2.
TipA shift left multiplies by 2, and a shift right divides by 2. For signed numbers, an arithmetic right shift copies the sign bit instead of shifting in 0, so 1100 (−4) becomes 1110 (−2).
Practice
An 8-bit SISO shift register runs on a 1 MHz clock. How long until a bit that goes in comes out?
Practice
How many clock edges does it take to load 4 bits serially into a 4-bit SIPO?
Serial communication
Sending bits one at a time over a single wire needs a PISO at the sender and a SIPO at the receiver. That's the heart of UART, SPI and I²C. A UART adds a start bit and a stop bit around each byte, so the receiver knows where it begins.
A UART sends 8 data bits plus a start and a stop bit at 9600 baud. Roughly how many bytes can it send per second?
Linear feedback shift registersGATE: fine to skip at first
Feed a shift register's input from an XOR of some of its outputs, and it steps through a long sequence that looks random. This is a linear feedback shift register (LFSR). With the right tap positions, an n-bit LFSR visits 2ⁿ − 1 states before repeating, and it needs just one gate. LFSRs generate test patterns, compute CRC checksums and scramble data.
> Loading the circuit…
A 4-bit LFSR with XNOR feedback from the top two bits. It visits 15 of the 16 states. Only 1111 is left out, and it would stay stuck there.
Keep pressing Clock edge. The display goes 1, 3, 7, E, D, B, 6, and so on, and it returns to 0 after 15 clocks.
Practice · GATE-style
What's the longest possible sequence of an 8-bit LFSR?
Practice · GATE-style
1011 (−5) is shifted right arithmetically by one place. What's the result?
Practice · GATE-style
A 16-bit word arrives serially at 2 Mbit/s into a SIPO. How long until the whole word is in?