------------------------------------------------------ -- ELETTRONICA DEI SISTEMI DIGITALI -- -- -- -- Soluzione Esercizio del 31/01/2001 -- ------------------------------------------------------ -- NOTA: Soluzione non verificata, potrebbe esistere un errore su qualche indice, -- si prega di verificare! library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; use IEEE.std_logic_unsigned.all; entity SHIFTER is port ( a : in unsigned(7 downto 0); s : in unsigned(3 downto 0); aol : in std_logic; b : out unsigned(7 downto 0) ); end SHIFTER; architecture SHIFT_P of SHIFTER is signal sh_left,sh_right : unsigned(7 downto 0); signal sh_count : unsigned(2 downto 0); signal sn : unsigned(3 downto 0); begin -- SHIFT_P process(a,s,aol) variable index,count : integer range 0 to 7; begin for i in 0 to 3 loop NG: sn(i) <= not s(i); end loop; -- CALCOLO DELLO SHIFT COUNT -- -- -- -- -- -- -- -- -- -- if s(3)='0' then sh_count <= s(2 downto 0); else sh_count <= sn(2 downto 0) + "001"; end if; count := Conv_integer(sh_count); SHIFT_LEFT: for i in 7 downto 0 loop if i>=count then index := i-count; sh_left(i) <= a(index); else sh_left(i) <= '0'; end if; end loop; -- i SHIFT_RIGHT: for i in 0 to 7 loop if i<=7-count then index:=i+count; sh_right(i) <= a(index); else sh_right(i) <= aol and a(7); end if; end loop; -- i end process; -- SHIFTOUT VALUE SELECTION MULTIPLEXER process(sh_left,sh_right,s) begin if s(3)='0' then b <= sh_left; else b <= sh_right; end if; end process; end SHIFT_P;