Mail Archives: djgpp/1999/03/25/12:10:02
Hi,(I do not need help)
here is my solution how to do bit rotation via inline assembly.
So, if this is stupid hint, don't beat my head, nor softly :-)
#ifdef __DJGPP__
#define roll(val,cnt) asm volatile (\
"movl %2, %%ecx \n\t" \
"roll %%cl, %1" \
:"=r" (val) \
:"r"(val), "r"(cnt) \
:"%ecx")
#endif /*__DJGPP__*/
let me explain:
"movl %2, %%ecx \n\t" \
"roll %%cl, %1" \
this is actual code. store number of bits in %cl using
whole %ecx. this is must, because roll needs 8 bit count.
both %ecx and %cl are prefixed with %%, beacause extended
asm is used.
:"=r" (val) \
store result back in in val
:"r"(val), "r"(cnt) \
attach arguments to registers (gcc choose automatically)
:"%ecx")
mark %ecx as clobbered - we used it explicitly.
Well, I really tested it on longs only, but this message is
meant more as hint than I expect you will use it. Also
I believe this can be done more elegant.
More you can find in Brennan's Guide too
http://www.rt.e-technik.tu-darmstadt.de/~georg/djgpp/djgpp-asm.htm
Any improvements are welcome
David
- Raw text -