Fixed shift

Draw a fixed left or right shift as bit wiring, marking discarded bits and fill positions. Apply a logical right shift and a signed arithmetic right shift to a negative value and check what zero fill and sign fill produce.

The collector scales an offset. In four-bit two’s complement, 1101 means −3. A right shift by one discards the low bit. The result depends on whether the high bit is filled with zero or a copy of the sign.

Move one place, then fill the vacated bit

Mode zero shifts left, discarding the old high bit and filling the low end with zero. 1101 becomes 1010. Mode one is logical right shift and fills with zero to give 0110. Mode two uses $signed(din) >>> 1 to replicate the sign bit. It gives 1110. Reserved mode three returns zero. Each shift moves one position. Mode chooses the result.

As two’s complement, 1110 is −2. SystemVerilog signed integer division truncates toward zero, so −3 / 2 gives −1. A signed arithmetic right shift by one corresponds to dividing by two and rounding down. With an unsigned din, din >>> 1 still fills with zero.

What fills the vacated bit after a shift?. D becomes A on left shift, 6 on logical right, E on arithmetic right
D becomes A on left shift, 6 on logical right, E on arithmetic right

Synthesizable SystemVerilog

module fixed_shift4 (
    input  logic [3:0] din,
    input  logic [1:0] mode,
    output logic [3:0] y
);
    always_comb begin
        case (mode)
            2'd0: y = din << 1;
            2'd1: y = din >> 1;
            2'd2: y = $signed(din) >>> 1;
            default: y = '0;
        endcase
    end
endmodule

Check the results against the waveform

Data is hexadecimal. Mode 0 is left shift, 1 logical right, 2 signed arithmetic right, and 3 zero output.

Change atdinmodey
0 nsD0A
10 nsD16
20 nsD2E
30 ns522
40 ns530
A right shift of 1101 gives 0110 with zero fill and 1110 with sign fill
The plot uses the VCD generated by the Icarus run.

For din=0101, both right shifts give 0010. Its sign bit is already zero, so this input alone cannot show how the fill rules differ.

Download the runnable SystemVerilog lab. Icarus checks the 5 rows above and 64 binary input combinations. It reads each directed result 1 ns after changing the inputs. The wait sets an observation time in the testbench. The waveform is functional evidence. Physical delay needs a timing model.

Interactive lab

Run D (1101) through all three shifts, then switch to 5. Compare the incoming high bit in each right shift.

Output (hex)
Show the last eight observations

    Teaching film

    Read the transcript

    Run the RTL yourself

    Extract the lab and follow the commands in its README. Compare the simulated outputs and waveform with your predictions from the interactive lab.

    Download Fixed shift RTL (.zip)

    Check your understanding

    1. What is four-bit 1101 after logical right shift by one?
    2. What are the result bits after signed arithmetic right shift of 1101 by one?
    3. Shift 1101 left by one and keep four bits. What is the result?
    4. What are signed integer −3 divided by 2 and arithmetic −3 shifted right by one?
    5. With unsigned din, what fills the high bit for din >>> 1?