使用VHDL移位运算符移位左寄存器:sll麻烦

时间:2016-04-13 02:57:27

标签: vhdl

library IEEE;
use IEEE.std_logic_1164.all;    
use IEEE.numeric_std.all;

entity shift_reg is 
    port(
    d : in std_logic;
    clk : in std_logic;
    rst_bar : in std_logic;
    q : out std_logic_vector(7 downto 0)
    );
end shift_reg;

architecture post_vhdl_08 of shift_reg is   
begin

    process(clk, rst_bar)  

    variable q_int : std_logic_vector(7 downto 0);

    begin
        if rst_bar = '0' then
            q_int := (others => '0');
        elsif rising_edge(clk) then
            q_int := q_int(6 downto 0) & d;
        end if; 

        q <= q_int;

    end process;

end post_vhdl_08;

我使用&#34; slice&#34;实现了带有串行输入和并行输出的左移位寄存器。实施转变;但我无法弄清楚如何使用重载的移位运算符来实现相同的逻辑:&#39; sll&#39; (左移逻辑)运算符。 谢谢大家提供的任何帮助。

2 个答案:

答案 0 :(得分:1)

以下是如何使用sll运算符作为示例。正如你所看到的那样,这是一种痛苦,因为它并没有做你想做的事情,还有其他的事情可以做:

process(clk, rst_bar)  

variable q_int : unsigned(7 downto 0);
subtype  st is unsigned(7 downto 0);

begin
    if rst_bar = '0' then
        q_int := (others => '0');
    elsif rising_edge(clk) then
        q_int := q_int sll 1;
        q_int := q_int or st'(0=>d,others=>'0');
        q <= std_logic_vector(q_int);
    end if; 
end process;

http://www.edaplayground.com/x/3YGu

因此,对于初学者来说,sll会移动'0',这不是您想要的。因此,您需要or操作才能包含d输入。但是sll std_logic_vector

} <{1}} {}} unsigned signed unsigned q if rising_edge )。不仅如此,这些类型的运算符在VHDL中执行strange things。所以,如果我是你,我会坚持连接。

此外,您对q的转让位置错误。当您执行顺序处理时,不得分配给public class MessageStatusToColorDrawableConverter : MvxValueConverter<bool, ColorDrawable> { protected override ColorDrawable Convert(bool value, Type targetType, object parameter, CultureInfo cultureInfo) { var context = Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity; // To get the context of the activity return value ? new ColorDrawable(new Color(ContextCompat.GetColor(context, Resource.Color.Pink))) : new ColorDrawable(new Color(ContextCompat.GetColor(context, Resource.Color.Green))); } } 之外的信号,因为否则(在这种情况下)<RelativeLayout android:id="@+id/relay_archive" android:layout_width="10dp" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:paddingLeft="10dp" android:paddingRight="10dp" local:MvxBind="Background MessageStatusToColorDrawable(Status)"> 将在两个时钟边沿上分配 - 不可合成的行为。

最后,根据你的合成器的能力,你可以得到16个触发器而不是8个。这是因为你的变量将合成8个触发器,你的信号将合成8个(&#34;每个在时钟控制过程中分配的信号推断出一个触发器&#34;)。然后,您将在合成器上回复以优化其中的8个触发器。

答案 1 :(得分:0)

我可以为你提供这种方法来左/右移动或使用旋转(VHDL&#39; 87!)..

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

entity Barrelshifter is

  generic (gSize : natural := 3);
  port (
    iPortA : in std_ulogic_vector(2**gSize-1 downto 0);
    oPortQ : out std_ulogic_vector(2**gSize-1 downto 0);
    iShiftDigits : in std_ulogic_vector(gSize-1 downto 0);
    iModeSelect : in std_ulogic_vector(1 downto 0)
    );

end Barrelshifter;

architecture Rtl of Barrelshifter is

begin   -- architecture Rtl 

  Comb: process (iPortA, iShiftDigits, iModeSelect)

  -- component variables
    variable Count : integer;  

  begin  -- process Comb


    Count := to_integer(unsigned(iShiftDigits));

    if iModeSelect = "00" then
        oPortQ <= std_ulogic_vector(shift_left(unsigned(iPortA), Count));

    elsif iModeSelect = "01" then
        oPortQ <= std_ulogic_vector(shift_right(unsigned(iPortA), Count));

    elsif iModeSelect = "10" then
        oPortQ <= std_ulogic_vector(rotate_left(unsigned(iPortA), Count));

    else
        oPortQ <= std_ulogic_vector(rotate_right(unsigned(iPortA), Count));

    end if;

  end process Comb;

end Rtl ;