1

Quoted from this question:

.text
    call start
    str:
        .string "test\n"
    start:
    movl    $4, %eax
    movl    $1, %ebx
    pop     %ecx
    movl    $5, %edx
    int     $0x80
    ret

gcc -c test.S gives :

test.S: Assembler messages:
test.S:8: Error: suffix or operands invalid for `pop'
Community
  • 1
  • 1
mysql_go
  • 2,269
  • 4
  • 20
  • 20

2 Answers2

2

pop is just the command. In at&t syntax you have to postpone the operand dimension. so you have to change the "pop" line with "popl"

Edit

  1. The correct answer is the one by Jens Björnhager as on my 64 bit laptop your code get correctly assembled by specifying it is a 32 bit architecture.
  2. The operand dimension is not mandatory but strongly advised.
David Costa
  • 1,738
  • 18
  • 33
  • @mysql_go you can find the answer here: http://www.x86-64.org/documentation/assembly.html in the "64-bit instructions" paragraph. It depends on your needs. – David Costa Apr 05 '11 at 20:39
1

You're probably on a 64 bit system trying to compile 32-bit assembly. Force gcc to compile 32 bits with -m32:

gcc -m32 -c test.S

Edit:

64-bit version:

.text
    call start
    str:
        .string "test\n"
    start:
    movl    $1, %eax
    movl    $1, %edi
    popq    %rsi
    movl    $5, %edx
    syscall

    movl    $60,%eax
    movl    $0, %edi
    syscall
Jens Björnhager
  • 5,632
  • 3
  • 27
  • 47
  • I thought all the 32bit instructions (including 16 bit ones) were still available on 64bit, but I was wrong. Here there is a webpage which explains why the popl instruction above doesn't work. http://www.x86-64.org/documentation/assembly.html – David Costa Apr 04 '11 at 19:16
  • it works,cool, but how can I use the output on a 64-bit machine? I tried to reproduce it using the output as http://stackoverflow.com/questions/5094934/loading-raw-code-from-c-program , but no it doesn't work. – mysql_go Apr 08 '11 at 13:38
  • That is 32-bit assembly, you need to rewrite everything to conform to the 64-bit ABI. I'm updating my answer with a x86-64 version of your program. – Jens Björnhager Apr 09 '11 at 00:43
  • but many 32-bit programe can also be run on 64-bit machines,right? – mysql_go Apr 13 '11 at 14:04