delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/17/18:15:24

From: Josh Vanderhoof <joshv AT planet DOT net>
Newsgroups: comp.os.msdos.djgpp,comp.os.linux.misc
Subject: Re: Floating point + inline assembly + C =?
Date: 16 Dec 1997 12:24:52 -0500
Organization: B.C. Equipment, Landing, NJ
Lines: 30
Sender: josh AT blorple
Message-ID: <m267opnqu3.fsf@planet.net>
References: <349675F3 DOT 2781E494 AT ic DOT ac DOT uk>
NNTP-Posting-Host: stan27.planet.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

"Mr R. Hopkins" <r.hopkins*@ic.ac.uk> writes:

> Hi there, I have an interesting problem:
> I am trying to write a short program which has some inline asm in gcc
> (either gcc on Linux or DJGPP on DOS). The problem I am having is
> passing a couple of floating point variables to the __asm__ part. What
> appears to happen when I use the suggested (by gcc info) method of:
> __asm__ (
> 	" fblahblah %1 \n"
> 	" faddstuff %%st(2), %%st(0) \n"
> 	" fldd %2 \n"
> 	" fstd %0 \n" /* etc. etc. */
> 	: "=r" (output_var)
> 	: "f" (input1), "f" (input2)
> 	: "%st" /* clobbers */
> );
> 
> This approach does not work, since in lines (2)and (3) above notice how
> the floating point stack gets shuffled about. This causes the input
> param %2 to be further down the stack than expected, and so the value
> of %st which gcc inserts for param %2 is now incorrect.
> As a consequence, the code produces unexpecte (an undesireable) answers.

Passing floating point parameters to asm on the x86 isn't very well
documented in the info file.  Get the source to gcc and read the
comment at the beginning of reg-stack.c.  That explains how gcc
adjusts the fp stack according to the asm args.

-- 
Josh Vanderhoof (joshv AT planet DOT net)

- Raw text -


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