Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to represent Integer greater than integer'high

Tags:

vhdl

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)

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 ?

Or, better asked: Whats the best way to declare a 32-bit (unsigned) integer supporting the operations >/<, =, +-/ ?

Tahnks in advance

Edit1: 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)

like image 397
mbrandalero Avatar asked Nov 18 '12 17:11

mbrandalero


2 Answers

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)

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.

like image 52
user_1818839 Avatar answered Oct 12 '22 15:10

user_1818839


use ieee.numeric_std.all;

and then use the unsigned data type - this operates as a bit vector with mathematical operations defined for it. You can choose how many bits you'd like. For example:

signal mynum : unsigned(234 downto 0)
like image 43
Martin Thompson Avatar answered Oct 12 '22 14:10

Martin Thompson