Mail Archives: djgpp/2000/06/21/07:28:35
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 -