Mail Archives: djgpp/2002/07/30/18:01:19
Hello Guys!
I've the following problem: I have written a small byte-swapping inline asm
routine which simple executes the i386-bswap on a longword. The best to
explain is i show the code:
//byte swapping func
static inline unsigned bswap(unsigned v)
{
unsigned register swapped;
__asm__ __volatile(
"bswapl %1\n"
: "=r"(swapped)
: "r"(v)
);
return swapped;
}
/* a crc-division function, which returns the reminder of the division at
the end (endian swapped)
*/
[..]
return bswap(r);
The code is optimized with -O2, the compiler inlines bswap nicely. In my
case r is located in ecx so the swapping code takes just 1 instruction.
Now the problem: the return statement doesnt move the result of bswap()
into eax, thus some garbage is returned.
However if i explicitly use eax as the input and output register in the
inline assembly, it works. Or if i alternatively do:
[..]
r = bswap(r);
return r;
this also works perfectly. So what have i done wrong, can anyone help?
Thanks,
Martin
- Raw text -