Quoted from this question:
.text
call start
str:
.开发者_Python百科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'
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
- 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.
- The operand dimension is not mandatory but strongly advised.
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
精彩评论