delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/06/21/07:28:35

From: pavenis AT lanet DOT lv
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>, djgpp AT delorie DOT com
Date: Wed, 21 Jun 2000 13:27:27 +0200
MIME-Version: 1.0
Subject: Re: Inline asm: lcall & various binutils versions
Message-ID: <3950C2BF.16877.34C3C3@localhost>
References: <394FDC74 DOT E8712E7F AT phekda DOT freeserve DOT co DOT uk>
In-reply-to: <Pine.SUN.3.91.1000621071322.8230C-100000@is>
X-mailer: Pegasus Mail for Win32 (v3.12c)
Reply-To: djgpp AT delorie DOT com

On 21 Jun 2000, at 7:20, Eli Zaretskii wrote:

> 
> On Tue, 20 Jun 2000, Richard Dawe wrote:
> 
> > #if GAS_MAJOR >= 2 && GAS_MINOR > 8
> > 		 "nop	\r\n"
> > #endif	/* IFDEFTEST */
> > 		 "nop	\r\n");
> 
> I understand that this is just an example, because in the actual problem 
> you had you will need a different condition for the versions (e.g., if 
> GAS_MAJOR is 3 or more, GAS_MINOR is not important).
> 
> > Is this
> > satisfactory? My sed knowledge is limited (*), but this seems to do the
> > trick.
> 
> The Sed scripts can be improved slightly, but they seem to be correct.
> 
> > It took me a while to work out how to put #ifdefs in inline assembly. Eli,
> > you probably knew this already, but: You have to rely on C's string
> > concatenation.
> 
> For inline assembly, you need to rely on the preprocessor to do the 
> trick when it works on the C source, so the #ifdef's need to be on the C 
> level, not on the assembly level.
> 
> > [ If you put '#ifdef' in the inline assembly, then it becomes an assembly
> > comment and does nothing.
> 
> AFAIK, inline assembly doesn't go through cpp; GCC emits it in the
> form of preprocessed assembly.  So you cannot have any preprocessor 
> directives inside the asm() block.

Wrong.

There are no problems using #ifdef and similar stuff inside inline 
assembler. Inline assembler is normally recognised by cc1 or cc1plus
so it's only after cpp have processed file. Try following example 
(change if needed):

#define TEST
#define FOO "inc %%eax"

int main (void)
{
    int foo = 1;
    asm ( "inc %%eax\t\n"
	  "inc %%eax\t\n"
#ifdef TEST
	  "inc %%eax\t\n"
#endif    
	  FOO "\t\n"
	  : "=a" (foo)
          : "a" (foo)
	);
    return foo;
}


Andris

- Raw text -


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