如何表示整数大于整数'high [英] How to represent Integer greater than integer'high
问题描述
有没有办法使用 STD_LOGIC_1164 或 STD_NUMERIC 中的预定义类型来表示从 0 到 2^32-1 的整数?(考虑到默认的整数类型范围从 -2^31-1 到 2^31-1)
Is there any way to use pre-defined types from STD_LOGIC_1164 or STD_NUMERIC to represent an integer ranging from 0 to 2^32-1 ? (considering the default integer type ranges from -2^31-1 to 2^31-1)
我需要实现 32 位计数器,并且正在寻找使用整数类型而不是 std_logic_vector 来保存代码的方法.. 任何设计模式?
I need to implement 32-bit counter and was looking for some way to save code using integer type instead of std_logic_vector.. Any design pattern for this ?
或者,最好问一下:声明支持操作的 32 位(无符号)整数的最佳方法是什么 >/<, =, +-/?
Or, better asked: Whats the best way to declare a 32-bit (unsigned) integer supporting the operations >/<, =, +-/ ?
提前感谢
Edit1:我发现的一个选项是将信号声明为 std_logic_vector(31 downto 0),并在进行比较或 +- 操作时执行转换.. 例如: counter <= counter + std_logic_vector(unsigned(value) +1)..还是没有找到除法的方法(以防万一,例如需要计数器值的1/4)
One option I found was to declare a signal as std_logic_vector(31 downto 0), and to perform conversions when doing comparisons or +- operations.. ex: counter <= counter + std_logic_vector(unsigned(value) + 1).. Still haven't found a way to do division though (in case,for example, 1/4 of the value of counter is needed)
推荐答案
使用 Integer 类型,您不能(至少,不可移植;可能有一些 VHDL 工具超出最小值并提供 64 位整数)
Using the Integer types, you cannot (at least, not portably; there may be some VHDL tools that go beyond the minimum and offer a 64-bit integer)
使用 IEEE.numeric_std,您可以声明一个具有完整 32 位范围(或 53 位,如果您愿意)的无符号,它应该可以满足您的所有需求.除非我误解了您的要求.
Using IEEE.numeric_std, you can declare an Unsigned with a full 32-bit range (or 53-bit if you wish) and it should do everything you want.need, unless I misunderstand what you are asking.
这篇关于如何表示整数大于整数'high的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!