2013-04-08 79 views
-2

我想使用Xilinx工具来定义和VHDL可以移动或旋转,向左或向右0,1,2或3位的位置模拟一个8位的移位器。我试图在digilent basys 2板上实现这一点。8位转换器-VHDL

我刚开始学习VHDL编程。任何人都可以帮忙吗? 任何人都可以告诉我vhdl代码应该是什么样子?

+2

听起来像给我作业。除此之外,还有大量的在线教程。只要搜索它。 – cb88 2013-04-08 17:49:40

回答

3

移位和旋转功能可以在numeric_std包中找到。下面是一些示例代码作为起点:

library IEEE; 
use IEEE.STD_LOGIC_1164.ALL; 
use IEEE.numeric_std.all; 


entity EXAMPLE is 
Port ( 
    clk : in STD_LOGIC; -- master clock 
    enable : in std_logic; -- when '1' --> rotate 
    dir : in STD_LOGIC; -- when '1': right, when '0': left 
    nr : in STD_LOGIC_VECTOR (1 downto 0); -- number of steps to rotate 
    din : in STD_LOGIC_VECTOR (7 downto 0); -- in vector 
    dout : out STD_LOGIC_VECTOR (7 downto 0)); -- out vector 
end EXAMPLE; 

architecture Behavioral of EXAMPLE is 

begin 

shifter: process(clk) 
begin 
    if rising_edge(clk) then 
     if enable='1' then 
     if dir='0' then -- right 
      dout<=std_logic_vector(rotate_right(unsigned(din),to_integer(unsigned(nr)))); 
     else -- left 
      dout<=std_logic_vector(rotate_left(unsigned(din), to_integer(unsigned(nr)))); 
     end if; 
     end if; 

    end if; 
end process shifter; 
end Behavioral; 
1

使用设计用于ieee.numeric_std library目的的功能。

使用(或CAST)的适当signedunsigned载体类型的输入。


下面是这些函数的“原型”,以便您可以看到您所得到的结果。

--============================================================================ 
    -- Shift and Rotate Functions 
    --============================================================================ 

    -- Id: S.1 
    function SHIFT_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED; 
    -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0) 
    -- Result: Performs a shift-left on an UNSIGNED vector COUNT times. 
    --   The vacated positions are filled with '0'. 
    --   The COUNT leftmost elements are lost. 

    -- Id: S.2 
    function SHIFT_RIGHT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED; 
    -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0) 
    -- Result: Performs a shift-right on an UNSIGNED vector COUNT times. 
    --   The vacated positions are filled with '0'. 
    --   The COUNT rightmost elements are lost. 

    -- Id: S.3 
    function SHIFT_LEFT (ARG: SIGNED; COUNT: NATURAL) return SIGNED; 
    -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0) 
    -- Result: Performs a shift-left on a SIGNED vector COUNT times. 
    --   The vacated positions are filled with '0'. 
    --   The COUNT leftmost elements are lost. 

    -- Id: S.4 
    function SHIFT_RIGHT (ARG: SIGNED; COUNT: NATURAL) return SIGNED; 
    -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0) 
    -- Result: Performs a shift-right on a SIGNED vector COUNT times. 
    --   The vacated positions are filled with the leftmost 
    --   element, ARG'LEFT. The COUNT rightmost elements are lost. 

    --============================================================================ 

    -- Id: S.5 
    function ROTATE_LEFT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED; 
    -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0) 
    -- Result: Performs a rotate-left of an UNSIGNED vector COUNT times. 

    -- Id: S.6 
    function ROTATE_RIGHT (ARG: UNSIGNED; COUNT: NATURAL) return UNSIGNED; 
    -- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0) 
    -- Result: Performs a rotate-right of an UNSIGNED vector COUNT times. 

    -- Id: S.7 
    function ROTATE_LEFT (ARG: SIGNED; COUNT: NATURAL) return SIGNED; 
    -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0) 
    -- Result: Performs a logical rotate-left of a SIGNED 
    --   vector COUNT times. 

    -- Id: S.8 
    function ROTATE_RIGHT (ARG: SIGNED; COUNT: NATURAL) return SIGNED; 
    -- Result subtype: SIGNED(ARG'LENGTH-1 downto 0) 
    -- Result: Performs a logical rotate-right of a SIGNED 
    --   vector COUNT times. 
2

Rotate Right = bitvector(0) & bitvector(7 downto 1); 
 
<br>Rotate Left = bitvector(6 downto 0) & bitvector(7);

使用级联其它功能都不能合成,能。