Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VHDL 'range => '0' command

Tags:

range

vhdl

fpga

Was hoping someone could answer my question. I came across this command in a VHDL code and was not sure what it does exactly. Could someone clarify the following?

if ( element1 = (element1'range => '0')) then

given that element1 is a 4 bit std_logic_vector, what is this condition saying? I could not find a direct answer for this in the few books I had or on google. Thanks!

like image 944
Engineer_Cynic Avatar asked Aug 13 '26 08:08

Engineer_Cynic


2 Answers

It's saying, create a temporary array aggregate the size of the range specified, with every element set to '0'. Whatever that range is.

Preventing accidents when the size of element1 changes.

EVERY time you see magic numbers like 3 downto 0, or for i in 0 to 3 loop ... try to replace them with this or equivalent, because for i in element1'range loop ... will never loop off the end of your array.

The defined range is necessary because the relational operator = (like <, > and the others) doesn't restrict its arguments to the same length, so the simpler form of aggregate (others => '0') doesn't work, because its size is undefined.

The condition will return true if element1 contains only '0'. It is a way of writing this that does not depend on the size of element1. In this case element1'range is 3 downto 0. If you were to change this to, for example, 5 downto 0, the if condition would still work.

like image 23
scary_jeff Avatar answered Aug 18 '26 15:08

scary_jeff