簡體   English   中英

使用GCC編譯時出現匯編錯誤

[英]Assembly error when compiling with GCC

使用此命令編譯.s文件時,出現“無此指令”錯誤:

$ gcc -s -o scall scall.s
scall.s: Assembler messages:
scall.s:2: Error: no such instruction: `section '
scall.s:4: Error: no such instruction: `global _start'
scall.s:7: Error: unsupported instruction `mov'
scall.s:8: Error: unsupported instruction `mov'
scall.s:11: Error: operand size mismatch for `int'
scall.s:13: Error: no such instruction: `section .data'
scall.s:15: Error: no such instruction: `msglength .word 12'

這是文件的代碼:

section .text
    global _start

_start:
    mov 4,%eax
    mov 1,%ebx
    mov $message,%ecx
    mov $msglength,%edx
    int  $0x80

section .data
   message: .ascii "Hello world!"
   msglength .word 12

如何擺脫錯誤?

我認為以下代碼將進行編譯(默認情況下,“ gcc”可以編譯.s和.S文件並將其鏈接到C庫,但是“ as”執行相同的操作,並且不將代碼與C庫鏈接)為:

.section .text
    .global _start
_start:
    mov $4,%eax
    mov $1,%ebx
    mov $message,%ecx
    mov msglength,%edx
    int  $0x80

    mov $1, %eax
    mov $0, %ebx
    int $0x80
.section .data
    message: .ascii "Hello world!"
    msglength: .word 12

GCC:

.section .text
    .global main
main:
    mov $4,%eax
    mov $1,%ebx
    mov $message,%ecx
    mov msglength,%edx
    int  $0x80

    mov $1, %eax
    mov $0, %ebx
    int $0x80
.section .data
    message: .ascii "Hello world!"
    msglength: .word 12

如下進行更正並使用-c參數gcc -c test.s -o test編譯

.text

_start:
.global main

main: 
    mov 4,%eax
    mov 1,%ebx
    mov $message,%ecx
    mov $msglength,%edx
    int  $0x80

.data
   message: .ascii "Hello world!"
   msglength: .word 12

暫無
暫無

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

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