vhdl

Type vs Subtype and down vs to for Integers in VHDL


What is the difference between type and subtype in VHDL and where should I use them?

My understanding is that subtype is just a narrowed down version of one of the primary types, such as integer:

subtype small_integer is integer range -128 to 127;

All the operations possible on primary type are also possible on subtypes (of course, with certain limitations). Also, it is better to use subtypes to prevent errors. So, what is the purpose of type?

Also, what is the difference between downto and to for the integers? (To get the point across, here is an example.)

subtype bit_index is integer range 31 downto 0;

subtype bit_index is integer range 0 to 31;

Thanks!


Solution