"Error: suffix or operands invalid for `push'" on 64bit boxes

Alok kataria alokkataria1@gmail.com
Thu Feb 22 11:50:00 GMT 2007


Hi,

I was trying some inline assembly with  gcc.

Running the assembly program on 64 bit system ( with 64bit gcc
version) gives errors of the form

/tmp/cc28kO9v.s: Assembler messages:
/tmp/cc28kO9v.s:57: Error: suffix or operands invalid for `push'

But the same thing on 32bit runs perfectly fine.

Here is the detailed report.
-----------------------------------------------------
Following is the program that i tried :

/* The important part is the temp function */


#include <stdio.h>

int f1 (int a)
{
        return a+5;
}

void f2 (int lock, int a)
{
        printf("\nans = %d\n", lock + a);
}


#define temp(lock) \
        asm volatile (  " push $0\n\t" \
                        " call f1\n\t" \
                        " push %0\n\t" \
                        " push %%eax\n\t" \
                        " call f2\n\t" \
                        " pop %%eax\n\t" \
                        " pop %%eax\n\t" \
                        " pop %%eax": : "r" (lock) : "memory", "%eax");


int main ()
{
        int lock = 10;
        temp (lock);
        return 0;
}
----------------------------------------------------------------------------
This compiles and works fine on a 32 bit system having

$ gcc --version
gcc (GCC) 4.1.1 20061011 (Red Hat 4.1.1-30)
Copyright (C) 2006 Free Software Foundation, Inc.

------------------------------------------------------------------------

But running it on a 64 bit system gives me following errors

$ gcc temp.c
/tmp/cc28kO9v.s: Assembler messages:
/tmp/cc28kO9v.s:57: Error: suffix or operands invalid for `push'
/tmp/cc28kO9v.s:58: Error: suffix or operands invalid for `push'
/tmp/cc28kO9v.s:60: Error: suffix or operands invalid for `pop'
/tmp/cc28kO9v.s:61: Error: suffix or operands invalid for `pop'
/tmp/cc28kO9v.s:62: Error: suffix or operands invalid for `pop'

Gcc version on this box is
$ gcc --version
gcc (GCC) 4.1.0 (SUSE Linux)
Copyright (C) 2006 Free Software Foundation, Inc.

$ file `which gcc`
/usr/bin/gcc: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV),
for GNU/Linux 2.6.4, dynamically linked (uses shared libs), for
GNU/Linux 2.6.4, stripped

I tried compiling this on a EM64t as well as on Opteron boxes and see
the same problem.

Is this a GCC problem, or anything wrong with my program.

Please let me know,

Thanks & Regards,
Alok

P.S. Please keep me cc'ed as i am not part of this list.



More information about the Gcc mailing list