--------------------------------------------------
--  8-bit Barrel Shifter implemented as a 
--  tree shifter with three stages
--
--  Alan R. Martello, University of Pittsburgh
--------------------------------------------------


entity BARREL is
    port (data_in:  in bit_vector(7 downto 0); 
          shift:    in bit_vector(7 downto 0);
          data_out: out bit_vector(7 downto 0)
         );
end BARREL;

architecture logic of BARREL is
    signal buffer_a, buffer_b: bit_vector(7 downto 0);
begin

   --
   --  stage one, shift one bit if needed
   --
   buffer_a(7 downto 0) <= 
       data_in(6 downto 0) & data_in(7) when shift(0)
       else data_in(7 downto 0);

   --
   --  stage two, shift two bits if needed
   --
   buffer_b(7 downto 0) <= 
       buffer_a(5 downto 0) & buffer_a(7 downto 6) 
       when shift(1) else buffer_a(7 downto 0);

   --
   --  stage three, shift four bits if needed
   --
   data_out(7 downto 0) <= 
       buffer_b(3 downto 0) & buffer_b(7 downto 4)
       when shift(2) else buffer_b(7 downto 0);

end logic;

<div align="center"><br /><script type="text/javascript"><!--
google_ad_client = "pub-7293844627074885";
//468x60, Created at 07. 11. 25
google_ad_slot = "8619794253";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br />&nbsp;</div>