OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Apr 29, 2024 8:15 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: high endian code for intel
PostPosted: Thu Sep 25, 2003 3:45 pm 
Hi, I need some ideas about how to mutate little endian values into high endian values, god d*** jpeg files use high endian byte order and does anybody have some trick to solve this problem otherwise Ill have to call a function for every value that I read from file. I know that it is not that hard to write that function but I need a fast function, some bit shifts would do my job. Illustration:

Ozguxxx: Im in a terrible trouble and I need help!
HQ: Hold on xxx, _programming_gurus are on the way to get you out...
Ozguxxx: I hope they wont be late, I have four days to get out of this hell.
HQ: I said hold on!!!
Ozguxxx: AAAAArggghhhh!!! dzzzzzzzzzzzzzzzzzz... {noise}
HQ: All _programming_gurus contact lost to Ozguxxx, help him, NOW!


Top
  
 
 Post subject: Re:high endian code for intel
PostPosted: Thu Sep 25, 2003 5:59 pm 
I don't think there is any bit-shifting trick (at least I'm not aware of one), because you're going to be reversing the byte order:

A
B
C
D

becomes

D
C
B
A

Just like there's no memmove trick (that I'm aware of)you can use to convert the string "ABCD" into the string "DCBA".

If it's practical, it might not be a bad idea to just use an already-written function like ntohl or ntohs, which should be reasonably efficient.


Top
  
 
 Post subject: Re:high endian code for intel
PostPosted: Fri Sep 26, 2003 1:47 am 
Offline
Member
Member

Joined: Sat Nov 25, 2006 12:50 am
Posts: 454
..


Last edited by Perica on Sun Dec 03, 2006 9:17 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re:high endian code for intel
PostPosted: Fri Sep 26, 2003 9:37 am 
If you're using C/C++, look for the macros htons(), htonl(), ntohs(), and ntohl(). They are probably in <netinet/in.h> on a *nix system, and possibly in the winsock headers on a *ows system.

These macros do conversion from "network byte order" (also known as 'big endian') to "native byte order", (also known as 'the right way round') and back. They will typically be coded as inline ASM for speed.

Hope this helps.


Top
  
 
 Post subject: Re:high endian code for intel
PostPosted: Fri Oct 03, 2003 4:44 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
at a lower level, doesn't the "XLATB" instruction of the CPU perform just the right transformation ?

_________________
Image May the source be with you.


Top
 Profile  
 
 Post subject: Re:high endian code for intel
PostPosted: Sat Oct 04, 2003 5:24 am 
Offline
Member
Member
User avatar

Joined: Fri Oct 22, 2004 11:00 pm
Posts: 1076
nah xlat is an index translation.

eg: if AL had 0x43, BX=0x100 its like doing mov al,b[bx + al] type thing...

probably why nody uses xlat, its a useless instruction :)

_________________
-- Stu --


Top
 Profile  
 
 Post subject: Re:high endian code for intel
PostPosted: Thu Oct 09, 2003 6:01 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 2:31 am
Posts: 5964
Location: In a galaxy, far, far away
oops . sorry. I always mix BSWAP (which should do what requested) and XLATB :-/

_________________
Image May the source be with you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group