Instead of Using the bit shift operators, we can use the assembly instruction bswap provided by x86 systems.
I am using the EAX Register for manipulation because it is the same register used for returning value. So i dont need any extra instruction to move my variable to EAX register
I am using the EAX Register for manipulation because it is the same register used for returning value. So i dont need any extra instruction to move my variable to EAX register
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using the X86 instruction bswap and gcc inline assembly | |
inline unsigned int ntohl(unsigned int x) | |
{ | |
asm("bswapl %1" : "=a" (x) : "a"(x)); | |
} | |
inline unsigned int htonl(unsigned int x) | |
{ | |
asm("bswapl %1" : "=a" (x) : "a"(x)); | |
} |
No comments:
Post a Comment