Re: "Error: suffix or operands invalid for `push'" on 64bit boxes
Andrew Haley <[email protected]> Thu, 22 Feb 2007 12:17:18 +0000
| Newsgroups | org.kernel.vger.linux-assembly |
|---|---|
| Message-ID | <[email protected]> |
[ redirect to gcc-help. Not appropriate for gcc ]
Alok kataria writes:
> 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;
> }
> 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.
x86-64 has a different assembly langauge and a different ABI.
On x86-64 your program should be written more like
xorl %%edi, %%edi
call f1
movl %0, %%edi
movl %%eax, %%esi
call f2
with clobbers where appropriate.
Andrew.