comp.lang.ada
 help / color / mirror / Atom feed
From: Dr Adrian Wrigley <amtw@linuxchip.demon.co.uk>
Subject: Re: Implementing an elegant range type.
Date: Wed, 21 Mar 2001 01:21:32 +0000
Date: 2001-03-21T01:21:32+00:00	[thread overview]
Message-ID: <3AB8021C.6DF5FB62@linuxchip.demon.co.uk> (raw)
In-Reply-To: wccofuwpics.fsf@world.std.com

Robert A Duff wrote:
> 
> Dr Adrian Wrigley <amtw@linuxchip.demon.co.uk> 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



  reply	other threads:[~2001-03-21  1:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-19 17:45 Implementing an elegant range type Chad R. Meiners
2001-03-19 18:38 ` Mark Lundquist
2001-03-19 20:50   ` Chad R. Meiners
2001-03-22 22:20     ` Nick Roberts
2001-03-23 22:29       ` Brian Rogoff
2001-03-20  4:48   ` Dr Adrian Wrigley
2001-03-20 15:31     ` Robert A Duff
2001-03-21  1:21       ` Dr Adrian Wrigley [this message]
2001-03-21  3:58         ` Brian Rogoff
2001-03-22 23:00         ` Array 'downto' [Was: Implementing an elegant range type] Nick Roberts
2001-03-26 18:28           ` Stephen Leake
2001-03-28 22:35           ` Robert A Duff
2001-03-21 22:55 ` Implementing an elegant range type Chad R. Meiners
  -- strict thread matches above, loose matches on Subject: below --
2001-03-20 20:17 Beard, Frank
2001-03-21 13:00 Francisco Javier Loma Daza
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox