NivaarExam PrepOfficial exam papers ↗

04-BS-8 · May 2018

Question 5 of 5: Barrel Shifter — Concept and a 4:1-MUX Realization

Nivaar worked solution (AI-drafted; not reviewed by a licensed engineer)

Notes on this paper

04-BS-8 Digital Logic Circuits — May 2018
National Exams, 3 hours, closed book (Casio or Sharp approved calculator only; one hand-written 8.5"×11" aid sheet, both sides, permitted). Format: five questions offered, each worth 25 marks (100 total); any four constitute a complete paper and only the first four appearing in the answer book are marked. All five are solved below for completeness.

Reference texts: Mano & Ciletti, Digital Design (6th ed., Pearson) — Boolean minimization, K-maps, PAL/PLA/FPGA architectures, flip-flop conversion, sequential-circuit design, arithmetic circuits; Floyd, Digital Fundamentals (11th ed., Pearson) — logic gates, multiplexers, shift registers, flip-flop characteristic tables.

Question 5: Barrel Shifter — Concept and a 4:1-MUX Realization (25 marks)

Question text not reproduced: the examination questions are © Engineers and Geoscientists BC. Open the official past paper (linked at the top of this page) to read the question, then follow the worked solution below.

Check

The source's own S1=S0=1 example gives Q1=D2 and then, two words later, also gives Q0=D1 — but its S1=S0=0 example (Q0=D0 when shifted 0) and S1=0,S0=1 example (Q0=D3 when shifted 1) both fit the single rule $Q_i=D_{(i-k)\bmod 4}$ for rotate-left-by-$k$ exactly, and that same rule requires $Q_0=D_{(0-3)\bmod4}=D_1$ AND $Q_2=D_{(2-3)\bmod4}=D_3$ at $k=3$ — the source's printed "Q2=D1" repeats the same D1 given for Q0 and is read here as a misprint; the internally-consistent value implied by the source's own $k=0,1$ examples is used instead: $Q_2=D_3$.

(a) A barrel shifter is a combinational circuit that shifts or rotates an $n$-bit word by any amount from 0 to $n-1$ positions in a single clock cycle (one gate-delay pass through a MUX network), instead of one bit-position per cycle the way a shift-register built from cascaded flip-flops would. Three advantages/applications: (1) Single-cycle ALU shift/rotate instructions — every general-purpose CPU's ALU uses a barrel shifter so a "shift left by 5" instruction costs one cycle, not five; (2) Floating-point normalization — aligning a mantissa after addition/subtraction requires shifting by an arbitrary, data-dependent amount, which a barrel shifter does in one step; (3) Cryptographic and CRC/hashing datapaths — algorithms such as AES and many hash functions require fixed, arbitrary bit-rotations of a word on every round, and a barrel shifter performs that rotation with fixed, predictable (data-independent) latency, which is also important for avoiding timing side-channels.

Given. $D_3D_2D_1D_0$ (data), $S_1S_0$ (rotate-left amount $k=0,1,2,3$), $Q_3Q_2Q_1Q_0$ (rotated output); worked examples for $k=0$ and $k=1$ given verbatim in the source.

Find. A minimum-part MSI realization and the complete routing table for all four shift amounts.

Approach. Generalize the source's own two worked examples into the single rule $Q_i=D_{(i-k)\bmod 4}$, tabulate all four columns, then realize each output bit as one 4:1 multiplexer (one MSI package per two outputs) whose four data inputs are wired per that output's column and whose select lines are the shared $S_1S_0$.

  1. Part (b), Step 1 — generalize the rotate rule. Rotating $D_3D_2D_1D_0$ left by $k$ positions moves the bit originally at position $j$ to position $(j+k)\bmod4$; equivalently, output position $i$ receives the bit that was $k$ positions to its right (with wraparound): $Q_i = D_{(i-k)\bmod 4}$. Checked against the source's own two examples: $k=0\Rightarrow Q_i=D_i$ (matches "Q3=D3,…,Q0=D0"); $k=1\Rightarrow Q_3=D_2,Q_2=D_1,Q_1=D_0,Q_0=D_3$ (matches verbatim, including "D3 is rotated around to the 0th output position").
  2. Part (b), Step 2 — complete routing table. Applying the same rule for $k=2,3$ gives the full 4-shift-amount table below; each row is what one 4:1 MUX's four data inputs must be wired to for that output bit.
    Barrel-shifter routing (rotate left by k = S1S0)
    S1 S0 (k)Q3Q2Q1Q0
    00 (0)D3D2D1D0
    01 (1)D2D1D0D3
    10 (2)D1D0D3D2
    11 (3)D0D3D2D1
  3. Part (b), Step 3 — MSI realization. Each output bit $Q_i$ is exactly a 4:1 multiplexer: its 4 data inputs are its table row above (in $k=0,1,2,3$ order onto the MUX's $I_0,I_1,I_2,I_3$ inputs) and its select lines are the shared $S_1S_0$. Four MUX channels are needed for the four outputs, realized with two 74LS153 (dual 4:1 MUX, 2 channels/package, common select) ICs — or four 74LS151 (single 8:1, using only 4 of 8 inputs) if only single-channel parts are on hand — with $S_1S_0$ bussed to every package's select pins. This needs zero discrete gates: the entire barrel shifter is two small MSI packages plus wiring, exactly as the question's closing hint suggests.
    MUX3D3D2D1D0Q3MUX2D3D2D1D0Q2MUX1D3D2D1D0Q1MUX0D3D2D1D0Q0S1,S0
    Fig. Q5(b) — four 4:1 MUX channels (2× 74LS153), each output $Q_i$ wired per its routing-table row, select lines $S_1S_0$ shared/bussed to all four.
Final results — Question 5
ItemResult
Rule$Q_i=D_{(i-k)\bmod4}$, $k=S_1S_0$
MSI part count2× 74LS153 (dual 4:1 MUX), zero discrete gates
k=2 rowQ3=D1, Q2=D0, Q1=D3, Q0=D2
k=3 rowQ3=D0, Q2=D3, Q1=D2, Q0=D1
Back to the paper →