首页 > 解决方案 > 如何使用 nasm 编译 x86 汇编代码?我收到一个错误

问题描述

我一直在尝试在 Linux 上学习 x86 汇编,这是我的代码:

.386
.model flat
.code
start PROC
    mov eax, 100
    add eax, 200

    ret
start endp
end start

每当我尝试用 nasm 编译它时,就像这样:

nasm -f elf32 -o <filename>.o <filename>.asm
ld -m elf_i386 -o <filename> <filename>.o

我收到此错误:

simple.asm:1: warning: label alone on a line without a colon might be in error [-w+orphan-labels]
simple.asm:1: error: attempt to define a local label before any non-local labels
simple.asm:2: error: attempt to define a local label before any non-local labels
simple.asm:2: error: parser: instruction expected
simple.asm:3: warning: label alone on a line without a colon might be in error [-w+orphan-labels]
simple.asm:3: error: attempt to define a local label before any non-local labels
simple.asm:4: error: parser: instruction expected
simple.asm:9: error: symbol `start' redefined
simple.asm:9: error: parser: instruction expected
simple.asm:10: error: parser: instruction expected

为什么我会收到这个错误?是编译器还是代码?以及如何解决?

标签: assemblyx86intel

解决方案


推荐阅读