我正在学习 VHDL,但我在尝试编写一些代码以满足边界检查异常时遇到了问题。

这是我的基本总结代码:

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_arith.all;
use IEEE.NUMERIC_STD.ALL;
use ieee.std_logic_unsigned.all;
...
port(
Address: in std_logic_vector(15 downto 0);
...
constant SIZE : integer := 4096;
variable addr: integer range 0 to SIZE-1 := 0;
...
process ...
addr := conv_integer(Address) and (SIZE-1); --error here

我得到的错误信息是



基本上,我的目标是制作一个 16 位地址总线,只有 4096 字节的引用内存。为什么我会收到这个奇怪的错误?我错过了一个图书馆包括什么的?

最佳答案

第一:不要使用 std_logic_arithnumeric_std 。还有 you don't need std_logic_arith

您不能对整数进行按位与运算,因此您需要执行以下操作:

addr := Address and to_unsigned(SIZE-1, Address'length);

但你可能想保证 SIZE 是 2 的幂

我倾向于做的是创建一个以位为单位的常量并从那里开始工作:
constant mem_bits : integer := 16;
constant SIZE     : integer := 2**16;

然后
addr := Address(mem_bits-1 downto 0);

关于syntax - 如何对 VHDL 中的整数进行按位与运算?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10388767/

10-13 01:36