🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.os.msdos.programmer
Article #2810

Re: Reversing Ints easily in TC++

#2810
From: Duncan Murdoch
Date: Fri, 26 Oct 1990 15:33
23 lines
1629 bytes
In article <i6TmR3w163w@doppler> jdries%doppler@faatcrl (J. Francis Dries, III) writes:
>I was hacking up a program to convert Sun Rasterfiles to GIF files when
>I ran into a little problem.  Almost all the non-Intel world (or so I'm
>told) writes ints MSByte first, whereas Borland's TC++ is
>reading/writing ints/longs (I need longs, since I'm working with 32bit
>ints from the Sun) LSByte first.
>
>My Question is, is there a way to reverse the order, quickly or cleanly?
>I could read in each char at a time and OR it onto the long and SHL all
>4 on, but that seems kinda sloppy to me.  I would think that the is a
>flag that can be set, or at least a built in macro...

The i486 has a new instruction BSWAP that does exactly what you want in 1
clock (if the data is already in a register), but I suppose that doesn't 
help you much. I'd do it by loading the two word sized parts, exchanging the 
bytes of each, and writing them out again.  Something like:

   mov ax, word ptr [data]
   mov dx, word ptr [data+2]
   xchg al,ah
   xchg dl,dh
   mov word ptr[data],dx
   mov word ptr[data+2],ax
Technical Details
Message-ID: <1990Oct26.153349.23581@maytag.waterloo.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!samsung!usc!zaphod.mps.ohio-state.edu!rpi!bu.edu!att!iuvax!maytag!watstat.waterloo.edu!dmurdoch
References: <i6TmR3w163w@doppler>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!samsung!usc!zaphod.mps.ohio-state.edu!rpi!bu.edu!att!iuvax!maytag!watstat.waterloo.edu!dmurdoch
From: dmurdoch@watstat.waterloo.edu (Duncan Murdoch)
Newsgroups: comp.os.msdos.programmer
Subject: Re: Reversing Ints easily in TC++
Keywords: Int, Intel, Motorola
Message-ID: <1990Oct26.153349.23581@maytag.waterloo.edu>
Date: 26 Oct 90 15:33:49 GMT
References: <i6TmR3w163w@doppler>
Sender: daemon@maytag.waterloo.edu (Admin)
Organization: University of Waterloo
Lines: 23