【问题标题】:What is negation (not) of a bit vector in VHDLVHDL中位向量的否定(非)是什么
【发布时间】:2011-02-03 03:22:46
【问题描述】:

在 VHDL 中对位向量求反是什么意思?例如,如果我有 10100111,它是一个名为 temp 的位向量,并且我执行类似 temp := not temp 之类的操作,我的输出将是什么?

【问题讨论】:

    标签: vector vhdl bit


    【解决方案1】:

    按位反转。

    一般在VHDL(LRM 7.2.1)中:“对于定义在一维数组类型上的一元运算not,对操作数的每个元素进行运算,结果是一个具有相同的数组索引范围作为操作数。”

    【讨论】:

      【解决方案2】:

      您可以在向量上使用“不”。只需使用 ModelSim 或 ISim 运行下面的程序,反转/取反的位向量就会在控制台中打印出来。

      LIBRARY ieee;
      USE ieee.numeric_bit.ALL;
      
      entity test is
      end entity test;
      
      architecture beh of test is
      
          function vec_image(arg : bit_vector) return string is
              -- original author Mike Treseler (http://mysite.ncnetwork.net/reszotzl/)
              -- recursive function call turns ('1','0','1') into "101"
              -------------------------------------------------------------------------------
              constant arg_norm        : bit_vector(1 to arg'length) := arg;
              constant center          : natural := 2;     --  123
              variable bit_image       : string(1 to 3);   --  '0'
              variable just_the_number : character;
          begin
              if (arg'length > 0) then
                  bit_image       := bit'image(arg_norm(1));   -- 3 chars: '0'
                  just_the_number := bit_image(center);              -- 1 char    0
                  return just_the_number                          -- first digit
                  & vec_image(arg_norm(2 to arg_norm'length)); -- rest the same way
                  else
                  return ""; -- until "the rest" is nothing
              end if;
          end function vec_image;
      begin
      
          demo:process is
              variable bitvec : bit_vector (7 downto 0) := "10100111";
          begin
              report vec_image(bitvec);
              report vec_image(not bitvec); -- not bit vector
              wait;
          end process demo;
      
      end architecture beh;
      

      【讨论】:

      • 谢谢,这正是我想要的。
      【解决方案3】:

      如果你真的想否定一个向量,你需要使用一个为它定义了某些属性的向量。具体来说:

      • 一些数值概念(因此您不能使用bit_vectorstd_logic_vector,它们只是位的集合)
      • “符号”的一些概念

      ieee.numeric_std 包中,您应该为此使用signed 类型:

      use ieee.numeric_std.all;
      ...
      variable a,b:signed(8 downto 0);
      ...
      a := "000000001";
      b := -a;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-11-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-25
        • 2014-07-14
        相关资源
        最近更新 更多