Mail Archives: djgpp/2000/06/21/11:30:26
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 -