From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6232d4984b20be17 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-03-20 17:26:06 PST Path: supernews.google.com!sn-xit-03!supernews.com!freenix!fr.usenet-edu.net!usenet-edu.net!news.tele.dk!195.224.53.60!nntp.news.xara.net!xara.net!gxn.net!server6.netnews.ja.net!server4.netnews.ja.net!news5-gui.server.ntli.net!ntli.net!news11-gui.server.ntli.net.POSTED!not-for-mail Message-ID: <3AB8021C.6DF5FB62@linuxchip.demon.co.uk> From: Dr Adrian Wrigley X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.2.14-5.0smp i686) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Implementing an elegant range type. References: <3ab6442f.0@silver.truman.edu> <7nst6.593482$U46.17851651@news1.sttls1.wa.home.com> <3AB6E116.BDD40E4B@linuxchip.demon.co.uk> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Wed, 21 Mar 2001 01:21:32 +0000 NNTP-Posting-Host: 62.253.132.124 X-Complaints-To: abuse@ntlworld.com X-Trace: news11-gui.server.ntli.net 985137587 62.253.132.124 (Wed, 21 Mar 2001 01:19:47 GMT) NNTP-Posting-Date: Wed, 21 Mar 2001 01:19:47 GMT Organization: ntl Cablemodem News Service Xref: supernews.google.com comp.lang.ada:5950 Date: 2001-03-21T01:21:32+00:00 List-Id: Robert A Duff wrote: > > Dr Adrian Wrigley writes: > > >...(could we have reverse [downto] ranges > > for arrays, like in VHDL please, while we're about it?). > > What does it mean? > > - Bob A fairly long post about various VHDL issues in relation to Ada... In VHDL, one typically writes things like: ------------------------------------ -- "downto" example type Byte is array (Integer range 7 downto 0) of Std_Logic; -- In this case, "Byte" has the following attributes: -- -- Byte'Low = 0 -- Byte'High = 7 -- Byte'Left = 7 -- Byte'Right = 0 for I in Byte'range loop -- counts from 7 to 0! end loop; ----------------------------------- -- "to" example type Octet is array (Integer range 0 to 7) of Std_Logic; -- In this case, "Octet" has the following attributes: -- -- Octet'Low = 0 Octet'High = 7 -- Octet'Left = 0 Octet'Right = 7 for I in Octet'range loop -- counts from 0 to 7 end loop; ----------------------------------- There is no 'First or 'Last attribute (as far as I remember!). You can also define integer types with "downto", similarly. Why? It seems to be so that programs that do I/O on arrays can display the most significant parts first. VHDL simulators display the 'Left element first (on the left), and the 'Right last. In the case of "Byte", therefore, bits are shown with bit 7 on the left as people expect. "Octet" would be displayed with bit 7 on the right. Conversion routines exist in standard libraries that convert to and from integers. I think they always take the 'Left value to be the MSB. When people declare arrays of values (not to be treated as bits in a byte), they usually want the lowest indexed value on the left. It is normal, therefore to represent (eg) a four byte register file as: type RegisterFile is array (0 to 3) of Std_Logic_Vector (7 downto 0); which will then be displayed in a simulator in the manner people expect (bytes in ascending order, bits in descending order). Are there any other reasons? -- I remember a time when most manufacturers' data sheets labeled bits 0 .. 7, where bit 0 was the LSB. But Texas Instruments tended to label bits from 1 to 8 with bit 8 being the LSB. The VHDL approach allows users to use whichever convention is appropriate. Now, however, everyone (including TI) seems to use the "7 downto 0" style. -- Why would I like it in Ada 0y? Simply to bring the languages even close together - I used to switch between the two quite frequently, and being almost, but not quite identical syntax is annoying. I also have written a VHDL -> Ada translator, which has the potential to allow hardware designs to migrate easily to software. Handling of "downto" in array indices is not trivial, and I have left this (very important!) feature out. Does anyone else out there use or have translators between the two languages? I can also see application for Ada -> VHDL translation, but this really has to be limited to a subset in practice (no dynamic creation of tasks, exceptions or generic subprogram parameters in VHDL). One unnecessary difference in VHDL is that variables are declared with the keyword "variable", as in variable X : Integer; This should be omitted, and signals be declared "X : signal Integer;", but this is probably not the right group to complain about VHDL syntax! -- Since VHDL is one of the worlds most succesful hardware languages, I think it has the potential to help introduce Ada to many engineers largely unaware of its existence. The numerous colleges that teach VHDL could easily justify teaching Ada95 as the "software counterpart". The benefits of "the Ada way" are very apparent when co-designing hardware and software using VHDL and C, where it is routine to find the VHDL clarity and type checking show how inefficient development in "C style" languages really is. There are some, however, who advocate using "C style" languages for hardware design, since people can leverage their familarity with C in the learning process. I do not agree with that approach. Hope this sheds some light on Ada's relationship to VHDL as seen by someone who has used both extensively in commerce (am I alone?). -- Adrian Wrigley