【问题标题】:Shift Left or Right on a variable of std_logic_vector在 std_logic_vector 的变量上左移或右移
【发布时间】:2019-04-29 16:42:16
【问题描述】:

我想知道是否可以对 std_logic_vector 类型的变量执行右移或左移

当我使用信号而不是变量时,我通常使用 shift_left 或 shift_right 函数,但我尝试在它们上使用它,但它不起作用,或者我做错了。

例如variable a : std_logic_vector(16 downto 0);

【问题讨论】:

  • 在 VHDL2008 中:sla - 左移算术 sra - 右移算术 sll - 左移逻辑 srl - 右移逻辑

标签: vhdl


【解决方案1】:

移位运算符(slasrasllsrl)都是为 type 定义的,独立于实例(signalvariable )。实际上,这些运算符可以在引用类型的任何地方使用,即使是 constantrecord 等。

例如,假设您有:

type my_record is record
  a : std_logic_vector(7 downto 0);
  b : std_logic_vector(3 downto 0):
end record my_record;

还有几个例子,例如:

architecture behav of foo is
  signal x : my_record;
begin

  process
    variable y : my_record;
  begin
    y.a := y.a sll 1;
    y.b := x.b srl 1;
  end process;
end architecture behav;

请注意,运算符可用于该类型的任何实例。这对于子程序甚至是可以接受的,例如:

function myfunc(a : std_logic_vector) return std_logic_vector is
begin
  return (a sll 5);
end function myfunc;

【讨论】:

    猜你喜欢
    • 2012-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-01
    • 1970-01-01
    相关资源
    最近更新 更多