This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Cannot for AREG register.


On Wed, 5 Nov 2003 y2bismil@engmail.uwaterloo.ca wrote:

> anyone know what is wrong with this, or another/easier way to do it:
>
> //extern uns POPV(void) ;
> #define POPV() \
>          ({int x; \
>          __asm__ __volatile__ ( \
>          "pop %%eax" \
>          : "=a" (x) \
>          : \
>          : "%eax" );x; })
>
> I'm trying to use the method suggessted by Kimmo Fredriksson to 'return'
> values.

I'm no inline assembler guru, so don't know what's wrong with your code,
but why not use this:

#define POPV() \
         ({int x; \
         __asm__ __volatile__ ( \
         "popl %0" \
         : "=r" (x)\
         : \
         );x; })

That is, why do you want to use %eax? Let gcc pick the register for you.
This

#include <stdio.h>
int main() {
  int x = POPV();
  printf("%d\n", x );
  return 0;
}

compiles on my machine to this:

main:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        andl    $-16, %esp
#APP
        popl %edx		# x = POPV()
#NO_APP
        subl    $8, %esp
        pushl   %edx
        pushl   $.LC0
        call    printf
        xorl    %eax, %eax
        leave
        ret

I.e. gcc has optimized the code and allocated x in register %edx.

Kimmo


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]