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

Assembly error when compiling with GCC

使用此命令编译 .s 文件时出现 "no such instruction" 错误:

$ 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  [=11=]x80

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

如何消除错误?

我认为下面的代码可以编译("gcc" 可以编译 .s 和 .S 文件,默认情况下 link 使用 C 库编译它们,但是 "as" 做同样的事情,不要' t link 代码与 C 库) 如:

.section .text
    .global _start
_start:
    mov ,%eax
    mov ,%ebx
    mov $message,%ecx
    mov msglength,%edx
    int  [=10=]x80

    mov , %eax
    mov [=10=], %ebx
    int [=10=]x80
.section .data
    message: .ascii "Hello world!"
    msglength: .word 12

gcc:

.section .text
    .global main
main:
    mov ,%eax
    mov ,%ebx
    mov $message,%ecx
    mov msglength,%edx
    int  [=11=]x80

    mov , %eax
    mov [=11=], %ebx
    int [=11=]x80
.section .data
    message: .ascii "Hello world!"
    msglength: .word 12

修改如下,编译时加上-c param gcc -c test.s -o test

.text

_start:
.global main

main: 
    mov 4,%eax
    mov 1,%ebx
    mov $message,%ecx
    mov $msglength,%edx
    int  [=10=]x80

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