delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/12/02/21:29:44

Date: Tue, 2 Dec 1997 18:28:16 -0800 (PST)
Message-Id: <199712030228.SAA21769@adit.ap.net>
Mime-Version: 1.0
To: Fabrice ILPONSE <fabrice AT trash DOT lip6 DOT fr>, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: Inline asm

At 01:51  12/1/1997 +0100, Fabrice ILPONSE wrote:
>Henri Ossi wrote:
>> 
>> A quick question.
>> Do I have to push and pop all the registers, which I use in inline asm?
>
>	You MUST !!
Not necessarily. In many cases you can use GCC's extended asm features to
inform it that a certain register has been clobbered. I can't think of a
simple realistic example, so here's an imaginary one. The `frob' instruction
does something useful and puts undefined stuff into the given register.
asm("frob %ebx" : /* no outputs */ : /* no inputs */ : "%ebx");

The advantage of this is that GCC will save and restore the register only if
it was actually using it. Alternatively, it may have a better way of doing
it (like reloading its previous contents from wherever they were in memory).
The only time you have to explicitly save and restore a register is if GCC
is not aware of its existence. The most usual example is %es. GCC assumes it
always contains the same as %ds, and never generates code which changes it.
>
>> What about return values?
>> Can I leave a number in ax to tell the calling function, if there was
>> any errors (etc)?
>> Or do I have to use a variable to store the number and then use
>> "return"?
>
>	I do it that way.
IMHO that's the best way. GCC will optimize it so that your result goes
straight into the return register, which I believe is %eax. This will
protect your code should that change in the future.

Nate Eldredge
eldredge AT ap DOT net



- Raw text -


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