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-Thread: 103376,9dec3ff1604723d9 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Nick Roberts" Newsgroups: comp.lang.ada Subject: Re: Bitordering? was Re: Bitmanipulation in Ada Date: Sat, 21 Aug 2004 12:34:46 +0100 Message-ID: References: <412665C4.E52A7590@alfred-hilscher.de> Mime-Version: 1.0 Content-Type: text/plain; format=flowed; delsp=yes; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de d5B6Gp2KRMAqM5VWp0tvQg0ZSOUCQPhd+b7lew15VaW8jDseY= User-Agent: Opera M2/7.51 (Win32, build 3798) Xref: g2news1.google.com comp.lang.ada:2908 Date: 2004-08-21T12:34:46+01:00 List-Id: On Fri, 20 Aug 2004 22:57:40 +0200, Alfred Hilscher wrote: > When I declare an boolean array with eight elements 1..8 (e.g. to > address a hardware port with eight status bits), how are they > ordered is X(1) the msb or the lsb of the byte? It is undefined. The typical way to deal with this kind of situation is to use a record type with a record representation clause. For example: type Frobnosticator_Status is record Ready, Complete, Motor_On, Fault, Power_Low: Boolean; end record; for Frobnosticator_Status'Bit_Order use System.Low_Order_First; for Frobnosticator_Status use record Ready at 0 range 0..0; Complete at 0 range 1..1; Motor_On at 0 range 3..3; Fault at 0 range 6..6; Power_Low at 0 range 7..7; end record; for Frobnosticator_Status'Size use 8; This lot specifies exactly where each bit is, and what it means. In this example, I've used representation clauses to tell the compiler to consider the LSB to be bit number 0 for this record, and to tell it that the record is 8 bits in size. I've associated a specific bit with each Boolean component (bits 2, 4, and 5 are unused). If I declare: Status: Frobnosticator_Status; for Status'Address use Frob_1_Status_Address; pragma Volatile(Status); to map the variable 'Status' to frobnosticator number 1's status port, I can read off its status bits by name: if Status.Fault then Put_Line( Current_Error, "Frob #1 went down" ); raise Hardware_Failure; end if; ... Does this help you? -- Nick Roberts