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.
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 at | din | mode | y |
|---|---|---|---|
| 0 ns | D | 0 | A |
| 10 ns | D | 1 | 6 |
| 20 ns | D | 2 | E |
| 30 ns | 5 | 2 | 2 |
| 40 ns | 5 | 3 | 0 |
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
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)