comp.lang.ada
 help / color / mirror / Atom feed
From: Simon Wright <simon@pushface.org>
Subject: Re: Little Endian -> Big Endian (Ada95 / GNAT)
Date: 26 Feb 2004 05:59:15 +0000
Date: 2004-02-26T05:59:15+00:00	[thread overview]
Message-ID: <x7vad36gz4c.fsf@smaug.pushface.org> (raw)
In-Reply-To: bac31daa.0402250138.fc4ed92@posting.google.com

jamesamor@hotmail.com (James Amor) writes:

> At present I am writing a tool to create a file which contains various
> extracted ELF symbols. The output data structure, a list of unsigned
> 32's, is to be used as part of an image on a PowerPC target.

If you output source code in your language of choice (C for this part
of the job, even!) you could compile it with the target compiler.

> Problem: As it is compiled on Wintel the tool is producing an output
> in little endian and PowerPC is big endian!
> 
> Question: How do I modify my code to write the output in big endian
> format?

Roughly,

with Ada.Streams;
with Ada.Unchecked_Conversion;
with Interfaces;
with System;

function To_Big_Endian
  (N : Interfaces.Unsigned_32) return Interfaces.Unsigned_32 is
begin
   if System."=" (System.Default_Bit_Order, System.Low_Order_First) then
      declare
         subtype Bytes is Ada.Streams.Stream_Element_Array (1 .. 4);
         function To_Bytes is new Ada.Unchecked_Conversion
           (Interfaces.Unsigned_32, Bytes);
         function From_Bytes is new Ada.Unchecked_Conversion
           (Bytes, Interfaces.Unsigned_32);
         B : constant Bytes := To_Bytes (N);
      begin
         return From_Bytes ((1 => B (4),
                             2 => B (3),
                             3 => B (2),
                             4 => B (1)));
      end;
   else
      return N;
   end if;
end To_Big_Endian;

(compiled but not tested)

-- 
Simon Wright                               100% Ada, no bugs.



  parent reply	other threads:[~2004-02-26  5:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-25  9:38 Little Endian -> Big Endian (Ada95 / GNAT) James Amor
2004-02-25 12:23 ` David C. Hoos
2004-02-26 15:43   ` James Amor
2004-02-26  5:59 ` Simon Wright [this message]
2004-02-27 20:38   ` Guillaume Foliard
2004-02-28 11:27   ` Little Endian -> Big Endian (Ada95 / GNAT), Whats with floating point types? Joachim Schr�er
2004-02-29 16:32     ` Simon Wright
2004-03-04  5:32     ` pburnand0-news
2004-03-04 11:55       ` Little Endian -> Big Endian (Ada95 / GNAT),Whats " David C. Hoos
2004-03-04 13:12         ` Little Endian -> Big Endian (Ada95 / GNAT), Whats " Marius Amado Alves
2004-03-04 17:51           ` Warren W. Gay VE3WWG
2004-03-04 18:34             ` Hyman Rosen
2004-03-05 17:40               ` Warren W. Gay VE3WWG
2004-03-05 17:50                 ` Warren W. Gay VE3WWG
2004-03-05 13:48             ` pburnand0-news
2004-03-05 17:34               ` Warren W. Gay VE3WWG
2004-03-05 17:53                 ` Warren W. Gay VE3WWG
2004-03-05 13:29           ` pburnand0-news
replies disabled

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