Mail Archives: djgpp/1997/04/11/19:35:22
On Thu, 10 Apr 1997 19:18:04 GMT, KaRNaGE
<dlydiard AT linknet DOT kitsap DOT lib DOT wa DOT us> wrote:
>
> i'm not sure on the watcom C inline asm syntax, so can someone convert the
> folowing short inline asm statement to djgpp inline asm? thankz...
>
> long fixed_mul(long num1, long num2);
> #pragma aux fixed_mul = \
> "imul edx" \
> "add eax, 8000h" \
> "adc edx, 0" \
> "shrd eax, edx, 16" \
> parm caller [eax] [edx] \
> value [eax] \
> modify [eax edx];
>
inline long
fixed_mul (const long _num1, const long _num2)
{
long tmp;
asm ("imull %%edx\n\t"
"addl $32768, %%eax\n\t"
"adcl $0, %%edx\n\t"
"shrdl $16, %%edx, %%eax"
: "=a" (tmp) /* output: eax->tmp */
: "a" (_num1), "d" (_num2) /* input: eax<-_num1, edx<-_num2 */
: "%edx" /* clobbered: edx */);
return tmp;
}
Here is another (let gcc choose register for one of operands):
inline long
fixed_mul (const long _num1, const long _num2)
{
long tmp;
asm ("imull %2\n\t"
"addl $32768, %%eax\n\t"
"adcl $0, %%edx\n\t"
"shrdl $16, %%edx, %%eax"
: "=a" (tmp)
: "a" (_num1), "r" (_num2) /* gcc chooses reg for _num2. */
: "%edx");
return tmp;
}
See the difference between them (gcc -S file.c will produce the
assembly listing in file.s).
Warning: Before using the above examples, test the output produced
by gcc.
Also, there is a DJGPP inline assembly tutorial (advised in FAQ):
http://www.rt66.com/~brennan/djgpp/djgpp_asm.html
- Raw text -