我想要一个位向量,我想要它的值为 2。我尝试了很多东西,但总是出错。现在我有这个:
variable var : bit_vector := B"00000000000000000000000000000100";
我收到这些错误:
can't match integer literal with type array type "bit_vector"
和
declaration of variable "var" with unconstrained array type "bit_vector" is not allowed
我怎样才能解决这个问题?谢谢。
最佳答案
你必须给var
一个范围(限制它),例如:
variable var : bit_vector(31 downto 0) ...
然后你可以为它分配一个常量,例如:
library ieee;
use ieee.numeric_bit_unsigned.all;
...
variable var : bit_vector(31 downto 0) := to_bit_vector(2, 32);
或以位串形式给出初始值,如:
variable var : bit_vector(31 downto 0) := "00000000000000000000000000000010";
to_bit_vector
的使用正如您所看到的,不太容易出错,因为示例代码中的常量不是 2,而是实际上是 4 ;-)
关于initialization - 如何在 VHDL 中初始化位向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20856493/