unsigned long routine(unsigned long x)
{
__asm("
addl %1,$1; movl %1,%0"
: "=g" (x)
: "g" (x));
return x;
}
The situation here is that the input parameter is %1
and the output parameter is %0. However, these are the
same. I have to include a "movl %1,%0" which really
translates to something like "mov eax,eax" and is a
complete useless instruction.
As far as I can see I need to assign the input and
output parameter to be the same. E.g. I need an I/o
parameter. How do I do that?
P.S. GCC does *not* optimize away the unneeded
statement. It is in the final, optimized code.
The second situation is as follows. Again, assume that
I want the same routine as above, but for unsigned
long long as in...
unsigned long long routine(unsigned long long x)
{
???
}
I have no clue here as to how I get x into a pair of
registers (which in a real routine, might be the same
register or not and might or might not occur at the
same time). I need to associate two input parameters
with (x) and two output parameters (again, quite
possibly the same). One for the bottom half and one
for the top half. How do I do that?
Thanks for any hints here. Getting inline assembly
working for GCC is definitely different.
> The second situation is as follows. Again, assume that
> I want the same routine as above, but for unsigned
> long long as in...
>
> unsigned long long routine(unsigned long long x)
> {
> ???
> }
The register designation "A" means edx:eax. Here's an example:
u64 rdtsc(void)
{
register u64 temp;
__asm__ __volatile__ (
"rdtsc \n\t"
: "=A" (temp)
);
return temp;
}