开发者

Why I can't compile this assembly successfully?

开发者 https://www.devze.com 2023-02-22 10:31 出处:网络
Quoted from this question: .text call start str: .开发者_Python百科string \"test\\n\" start: movl$4, %eax

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

  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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消