delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/06/21/11:30:26

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 17:00:37 +0200
MIME-Version: 1.0
Subject: Re: Inline asm: lcall & various binutils versions
Message-ID: <3950F4B5.10728.2A871B@localhost>
References: <3950C2BF DOT 16877 DOT 34C3C3 AT localhost>
In-reply-to: <Pine.SUN.3.91.1000621152921.13853B-100000@is>
X-mailer: Pegasus Mail for Win32 (v3.12c)
Reply-To: djgpp AT delorie DOT com

On 21 Jun 2000, at 15:33, Eli Zaretskii wrote:

> 
> On Wed, 21 Jun 2000 pavenis AT lanet DOT lv wrote:
> 
> > > 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.
> 
> This is a misunderstanding: what I meant to say was that the inline 
> assembly doesn't go through preprocessor *after* cc1 or cc1plus wrote it 
> to the output, i.e. between cc1 and Gas.
> 
> It goes without saying that the C/C++ source itself goes through 
> preprocessor.  But at that stage, the asm is not interpreted except for 
> constraints and clobber lists.
> 
> > #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;
> > }
> 
> In this example, the preprocessor directives are on the C level, not on 
> the assembly level.  To be on assembly level, they would need to be 
> inside the quoted assembly code, not outside it.
> 
> I'm sorry if my wording was unclear.

I think for this case (adding * for indirect jumps or far calls) possibility 
to use preprocessor before compiling source is enough

#if  (BNU_MAJOR==2 && BNU_MINOR>=10) || BNU_MAJOR>2
#define 	INDIRECT_CALL_PREFIX  "*"
#else
#define  	INDIRECT_CALL_PREFIX  ""
#endif

....

asm (.....

		"call	"INDIRECT_CALL_PREFIX"%eax\t\n"

	...);

Of course getting BNU_MAJOR and BNU_MINOR defined is a 
different topic...

Andris

- Raw text -


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