Vector 什么是VHDL中位向量的求反(非)
在VHDL中对位向量求反意味着什么?例如,如果我有10100111,这是一个名为temp的位向量,我做了类似temp:=nottemp的事情,那么我的输出是什么 可以对向量使用“not”。只需使用ModelSim或ISim运行下面的程序,反转/反位向量将在控制台中打印Vector 什么是VHDL中位向量的求反(非),vector,vhdl,bit,Vector,Vhdl,Bit,在VHDL中对位向量求反意味着什么?例如,如果我有10100111,这是一个名为temp的位向量,我做了类似temp:=nottemp的事情,那么我的输出是什么 可以对向量使用“not”。只需使用ModelSim或ISim运行下面的程序,反转/反位向量将在控制台中打印 LIBRARY ieee; USE ieee.numeric_bit.ALL; entity test is end entity test; architecture beh of test is function
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;
一个稍微聪明的反转
通常在VHDL(LRM 7.2.1)中:“对于一维数组类型上定义的一元操作而不是,操作在操作数的每个元素上执行,结果是一个索引范围与操作数相同的数组。”如果确实要对向量求反,您需要使用定义了某些属性的向量。具体而言:
- 数值的一些概念(因此不能使用
位向量
或标准逻辑向量
,它们只是位的集合)
- “符号”的一些概念
从ieee.numeric_std
软件包中,您应该使用签名的
类型:
use ieee.numeric_std.all;
...
variable a,b:signed(8 downto 0);
...
a := "000000001";
b := -a;
谢谢,这正是我想要的。