使用GCC进行编译时出现装配错误

时间:2015-02-03 10:54:38

标签: c gcc assembly

我得到"没有这样的指示"使用此命令编译.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

如何摆脱错误?

2 个答案:

答案 0 :(得分:2)

我认为下面的代码将编译(“gcc”可以编译.s和.S文件,默认情况下用C库链接它们,但“as”做同样的事情并且不用C库链接代码) as:

.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

答案 1 :(得分:0)

按如下方式更正并使用-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  $0x80

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