comp.lang.ada
 help / color / mirror / Atom feed
From: ncohen@watson.ibm.com (Norman H. Cohen)
Subject: Re: How does Alsys index bit-arrays on Intel ?
Date: Tue, 23 Mar 1993 15:29:18 GMT
Date: 1993-03-23T15:29:18+00:00	[thread overview]
Message-ID: <C4CLou.I5z@watson.ibm.com> (raw)
In-Reply-To: 1993Mar23.023912.1083@rational.com

In article <1993Mar23.023912.1083@rational.com>,
rlk@Rational.COM (Robert Kitzberger) writes: 

|> In order to determine the ordering empirically (the only way I'd trust ;-),
|> I'd write a test case, and watch what happens on a logic
|> analyzer.  If no logic analyzer exists, then write some assembly code
|> that accepts a bit number and an object, and tests whether that bit
|> is a zero or a one (this way you can explicitly control the bit ordering).
|> Then, create a dummy object and display it's contents as reported by your
|> assembly routine: 
|>
|>   object := #1234_5678#;
|>   for I in bits loop
|>       if assy_bit_is_on( object, I ) then      <---implement in assembly
|>        put("1");
|>       else
|>        put("0);
|>       end if;
|>   end loop;

Logic analyzer?  Assembly routine?  A straightforward test can be written
entirely in Ada: 

   with Text_IO; use Text_IO;
   with Unchecked_Conversion;

   procedure Test_Bit_Numbering is

      type Bit is (Zero, One);
      for Bit use (Zero => 0, One => 1);
      for Bit'Size use 1;

      type Bit_Vector is array (Natural range <>) of Bit;
      pragma Pack(Bit_Vector);

      type Word_Type is
         record
            Bit_Zero   : Bit;
            Other_Bits : Bit_Vector(0 .. 30);
         end record;

      for Word_Type use
         record
            Bit_Zero   at 0 range 0 .. 0;
            Other_Bits at 0 range 1 .. Integer'Size-1;
         end record;

      for Word_Type'Size use Integer'Size;

      function Word_To_Integer is
         new Unchecked_Conversion (Word_Type, Integer);

      Word : Word_Type;

   begin

      Word.Bit_Zero := One;
      Word.Other_Bits := (0 .. 30 => Zero);

      if Word_To_Integer(Word) = 1 then
         Put_Line ("Bit zero is the low-order bit.");
      else
         Put_Line ("Bit zero is the high-order bit.");
      end if;

   end Test_Bit_Numbering;

I believe the original question was about numbering the components used
in Boolean arrays rather than about numbering the bits in
record-representation clauses.  It should be obvious how to modify this
program to answer the array-component question too.

--
Norman H. Cohen    ncohen@watson.ibm.com



  reply	other threads:[~1993-03-23 15:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-03-19 19:34 How does Alsys index bit-arrays on Intel ? Dave Bashford
1993-03-22 19:16 ` john r strohm
1993-03-23  2:39   ` Robert Kitzberger
1993-03-23 15:29     ` Norman H. Cohen [this message]
1993-03-23 20:27       ` john r strohm
1993-03-25 22:09         ` Dave Bashford
replies disabled

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