www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/11/19:35:22

From: bukinm AT inp DOT nsk DOT su (Michael Bukin)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: watcom asm->djgpp asm help
Date: Fri, 11 Apr 1997 14:36:57 GMT
Organization: BINP SD RAS
Lines: 60
Message-ID: <334e4654.42717905@news-win.inp.nsk.su>
References: <Pine DOT GSO DOT 3 DOT 96 DOT 970410121408 DOT 7948A-100000 AT linknet DOT kitsap DOT lib DOT wa DOT us>
Reply-To: bukinm AT inp DOT nsk DOT su
NNTP-Posting-Host: csd-bsdi.inp.nsk.su
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019