-- Arithmetic shift right example (sra)
library ieee;
use ieee.std_logic_1164.all;
-- Use Warp's below package so can do math with std_logic_vector's
use work.std_arith.all; 

entity SHIFT is port(
	ShiftIn, Clk, ShiftEnable:	in std_logic;
	ShiftOut:	out std_logic;
	Q:	buffer std_logic_vector(7 downto 0)
);
end SHIFT;

architecture behavior of SHIFT is

--procedure declaration
procedure SHIFT_RIGHT(signal Q: buffer std_logic_vector(7 downto 0);
	signal ShiftIn:	in std_logic; 
	signal ShiftOut:	out std_logic;
	signal ShiftEnable: in std_logic;
	signal clk: in std_logic) is
	begin
		if RISING_EDGE(clk) then
			case ShiftEnable is
				when '1' => 
					ShiftOut <= Q(0);
					Q <= Q srl 1;
					Q(7) <= ShiftIn;	
				when '0' => 
					Q <= "00000000";
				when others =>
					Q <= "00000000";
			end case;
		end if;
end procedure;

begin
	SHIFT_RIGHT(Q,ShiftIn,ShiftOut,ShiftEnable,Clk);
end behavior;


