delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/08/21:54:02

Date: Wed, 8 May 1996 21:51:34 -0400
From: dj (DJ Delorie)
Message-Id: <199605090151.VAA15112@delorie.com>
To: salvador AT inti DOT edu DOT ar
CC: djgpp AT delorie DOT com
In-reply-to: <9605081434.aa25285@ailin.inti.edu.ar> (salvador@inti.edu.ar)
Subject: Re: Problems with inline asm of GCC 2.7.2

>   But if i replace the lines with // * for:
> 
> asm ("Jcxz  countLines__2");

I hope you meant jecxz, not jcxz.


> asm ("Scasb":::"%ecx","%edi");
> 
>  Tells to GCC that this line touchs the ECX and EDI registers, but the same
> syntax under C++ reports:

put spaces between the colons.

>  asm ("Incl %%edx":::"%edx");

I think you wanted this:

	asm("incl %0", "g" (a));

Let the compiler worry about which register it goes in.

> 4) If i put:
> 
> asm ("Movw $0,%%es":::"%es"); (I don't want to do that is only an example ;)
> 
>   I get:
> 
> pp3.c: In function `pepe':
> pp3.c:8: unknown register name `%es' in `asm'

Try "es" not "%es" for the trashed register list.  See <sys/farptr.h>
for an example of using segment registers in asm.  I think gcc might
just not care about them; it rarely uses them itself.

> * ES=DS, at any time.

In mainline code, yes, but I wouldn't put money on it.  In interrupt
handlers and deep in the heart of libc, no.

> * GS and FS can be used for any function but this function *must* restore the
> original value before return (of course i exclude the farptr macros).

Libc uses only %gs, and it makes no assumptions about its original
value.

> * EDI, ESI and EBX must be restored.

And %ebp.

> * ECX, EDX and EAX can be used.

Yes, for functions.  Not for inline asm - you must tell gcc which
registers you use, and it will work around them.

> * EAX is the return value.

Depends on the return type.  Floats are returned on the FPU stack;
structures are returned in various places depending on size and
structure. 64-bit returns in edx:eax.

> * If i alter ES, and don't restore the value, the program crash.

Most likely.

> * I can use GS and FS like globals variables in all my application (this
> excludes: functions called from any library, interrupt routines and routines
> for libraries).

No.  Libc modifies %gs and does not restore it.  Libc avoids touching
%fs, but <sys/farptr.h> modifies that and doesn't restore it.

- Raw text -


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