1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity uni_reg is
Port ( clk : in STD_LOGIC;
D : in STD_LOGIC_VECTOR (2 downto 0); -- Parallel input
DSL : in STD_LOGIC; -- Left-coming bit
DSR : in STD_LOGIC; -- Right-coming bit
S : in STD_LOGIC_VECTOR (1 downto 0); -- Modes (nothing, shift right, shift right, store input)
Q : out STD_LOGIC_VECTOR (2 downto 0)); -- Parallel output
end uni_reg;
architecture Behavioral of uni_reg is
signal Q_now, Q_next : STD_LOGIC_VECtOR (2 downto 0);
begin
-- Combinatorial
process (S, DSL, DSR, D, Q_now)
begin
if S = "00" then
Q_next <= Q_now;
elsif S = "01" then
Q_next <= DSL & Q_now(1 downto 0);
elsif S = "10" then
Q_next <= Q_now(2 downto 1) & DSR;
else
Q_next <= D;
end if;
end process;
-- Register
process (clk)
begin
if rising_edge(clk) then
Q_now <= Q_next;
end if;
end process;
Q <= Q_now;
end Behavioral; |
Partager