Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Inline assembly

0 views
Skip to first unread message

Michael Lee Finney

unread,
Jun 21, 2001, 11:04:07 PM6/21/01
to
Hi, I am trying to use inline assembly with GCC. I
have the basics figured out, but have a couple of
questions. First, suppose that I have a routine as
follows...

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.

Timur Tabi

unread,
Jun 22, 2001, 12:28:22 PM6/22/01
to
Michael Lee Finney wrote:

> 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;
}

Michael Lee Finney

unread,
Jun 23, 2001, 12:01:13 AM6/23/01
to
In article <3B337226...@interactivesi.com>,
tt...@interactivesi.com says...


Thank you.

0 new messages