跳转到内容

FPGA 设计的 VHDL/4 位移位寄存器

来自维基教科书,开放书籍,开放世界

4 位移位寄存器

[编辑 | 编辑源代码]
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Shift_register_VHDL is

   port( clk: in std_logic;
 	 L: in std_logic; 
 	 w: in std_logic; -- new data to shift in
 	 Output: out std_logic_vector(3 downto 0);
 	 Input: in std_logic_vector( 3 downto 0));

end Shift_register_VHDL;

architecture Behavioral of Shift_register_VHDL is
begin
   process
   variable temp: std_logic_vector(3 downto 0); 
   begin
      wait until rising_edge (clk);
      temp := Input; 
      if L='1' then 
         for i in 0 to 2 loop
            temp(i) := temp(i+1);
         end loop;
         temp(3) := w;
      end if;
      Output <= temp;
    end process;
end Behavioral;

仿真结果

[编辑 | 编辑源代码]
 
华夏公益教科书