簡體   English   中英

為什么我不能成功編譯該程序集?

[英]Why I can't compile this assembly successfully?

引自這個問題

.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給出:

test.S: Assembler messages:
test.S:8: Error: suffix or operands invalid for `pop'

pop只是命令。 在at&t語法中,您必須推遲操作數維。 因此您必須將“ pop”行更改為“ popl”

編輯

  1. 正確的答案是JensBjörnhager的答案,因為在我的64位筆記本電腦上,通過指定32位體系結構可以正確地匯編代碼。
  2. 操作數維不是強制性的,但強烈建議使用。

您可能正在嘗試編譯32位程序集的64位系統上。 強制gcc使用-m32編譯32位:

gcc -m32 -c test.S

編輯:

64位版本:

.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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM