Home > VHDL > Shift Registers > Simple barrel shifter

Simple barrel shifter

Figure below shows the barrel shifter. In this case, the circuit shifts the input vector either 0 or 1 position to the left. When shift = 1, the LSB bit filled with '0' and when shift = 0, then outp = inp. When shift = 1, then outp(0) = '0' and outp(i) = inp(i - 1). The VHDL code of barrel shifter is shown bellow.

Fig-Simple-barrel-shifter.png

LIBRARY ieee;

USE ieee.std_logic_1164.all;

ENTITY barrel IS

GENERIC (n: INTEGER := 8);

PORT ( inp: IN STD_LOGIC_VECTOR (n-1 DOWNTO 0);

shift: IN INTEGER RANGE 0 TO 1;

outp: OUT STD_LOGIC_VECTOR (n-1 DOWNTO 0));

END barrel;

ARCHITECTURE RTL OF barrel IS

BEGIN

PROCESS (inp, shift)

BEGIN

IF (shift=0) THEN

outp <= inp;

ELSE

outp(0) <= '0';

FOR i IN 1 TO inp'HIGH LOOP

outp(i) <= inp(i-1);

END LOOP;

END IF;

END PROCESS;

END RTL;