使用 GCC 编译时出现汇编错误

nel*_*has 3 c assembly 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'
Run Code Online (Sandbox Code Playgroud)

这是文件的代码:

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
Run Code Online (Sandbox Code Playgroud)

我怎样才能摆脱错误?

Par*_*ani 5

我认为以下代码将编译(“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
Run Code Online (Sandbox Code Playgroud)

海湾合作委员会:

.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
Run Code Online (Sandbox Code Playgroud)