移位寄存器设计

“FOR-LOOP语句”和“信号并置与赋值语句”任选其一,设计8位移位寄存器。

要求:
(1)在时钟CLK上升沿触发下,M=00,实现并行置数;M=01,实现左移;M=10实现右移。
(2)串行输入数据为DIN,并行8位预置数为data,串行输出端为output。
(3)rst为使能端:rst=0,则寄存器清零,否则将正常工作。

写出代码,给出编译通过截图。

library ieee;

use ieee.std_logic_1164.all;



entity shift_reg_8 is

    port( CLK : in std_logic;

          RST : in std_logic;

          M : in std_logic_vector(1 downto 0);

          --00    load

          --01    left

          --10    right

          DIN : in std_logic;

          DATA : in std_logic_vector(7 downto 0);

          TEST : out std_logic_vector(7 downto 0);

          OUTPUT : out std_logic);

end shift_reg_8;



architecture BHV of shift_reg_8 is

    signal REG : std_logic_vector(7 downto 0) := (others => '0');

begin

    process(CLK, RST)

    --variable REG : std_logic_vector(7 downto 0) := (others => '0');

    begin

        if (RST = '0') then

            REG <= (others => '0');

        elsif rising_edge(CLK) then

            case M is

                when "00" =>

                    --load

                    REG <= DATA;

                when "01" =>

                    --left

                    REG <= REG(6 downto 0) & DIN;

                when "10" =>

                    --right

                    REG <= DIN & REG(7 downto 1);

                when "11" =>

                    --hold

                    REG <= REG;

                when others =>

                    null;

            end case;

        end if;

        OUTPUT <= REG(7);

        TEST <= REG;

    end process;    

end BHV;

代码缺少右移串行输出




扫一扫在手机打开当前页