www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/10/18:08:16

From: Andrew Crabtree <andrewc AT typhoon DOT rose DOT hp DOT com>
Message-Id: <199704102201.AA151499663@typhoon.rose.hp.com>
Subject: Re: watcom asm->djgpp asm help
To: dlydiard AT linknet DOT kitsap DOT lib DOT wa DOT us (KaRNaGE)
Date: Thu, 10 Apr 1997 15:01:03 PDT
Cc: djgpp AT delorie DOT com
In-Reply-To: <Pine.GSO.3.96.970410121408.7948A-100000@linknet.kitsap.lib.wa.us>; from "KaRNaGE" at Apr 10, 97 12:18 (noon)

> 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];

I know nothing of watcom syntax (or GAS syntax really)
but it looks simple enough to take a guess at (if I'm wrong 
somebody please correct me, this would be good to know)  

The last three lines appear to be watcom specific commands that
specify that 

1) num1 and num2 are passed in through eax and adx (not the case
in GCC)
2) The return value goes in eax
3) It uses eax and edx

The first instruction "imul edx" works as long as 
your two values are already in EAX and EDX. 
I remember reading a post from Robert H
about how to call through registers ( search the list) but
it would probably be easier to just mov the values off the 
stack into eax and edx.  

If you want to use GAS create a C program like this

long fixed_mul(long num1, long num2)
{  return (num1 * num2);
}

Compile with -S and then add in the code that checks and corrects 
for overflow (the add 0x8000, add with carry, and shift).  You also
probably want to delete the stack frame it creates as well since this is
for speed, right ( there is a command line option to kill this).



If you are using NASM (which may be easier) try this

fixed_mul.s

[BITS 32]
[GLOBAL _fixed_mul]
[SECTION .text]
_fixed_mul :
	mov EAX, [ ESP + 4]
	mov EDX, [ ESP + 8]
        imul EDX
	... (overflow code should work as is)
	ret 

> nasm -f coff fixed_mul.s -o fixed_mul.o

And then add fixed_mul.o to your link line.

I don't know gcc inline assembly well enough to help you out there,
but this should give a pretty fast function.  Maybe the allegro 
sources have a macro version of fixed routines (?)

Andrew






- Raw text -


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