Assembly 无法编译简单的应用程序

Assembly 无法编译简单的应用程序,assembly,nasm,Assembly,Nasm,我正在尝试为Linux Arch x64编译此文件,我正在尝试: section .text global _start _start: mov edx, len mov ecx, msg mov ebx, 1 mov eax, 4 int 0x80 mov eax, 1 int 0x80 section .data msg db 'hi123', 0xa len equ $ -

我正在尝试为Linux Arch x64编译此文件,我正在尝试:

section .text
global _start
_start:
        mov edx, len
        mov ecx, msg
        mov ebx, 1
        mov eax, 4
        int 0x80

        mov eax, 1
        int 0x80

section .data
msg db 'hi123', 0xa
len equ $ - msg

但有一个错误:

/usr/bin/ld: i386 architecture of input file `test1.o' is incompatible with i386:x86-64 output

在x86_64上链接32位应用程序时,将仿真设置为elf_i386可提供正确的elf格式。因此,例如,如果您使用nasm-f elf file.asm-o file.o编译汇编程序应用程序,则link命令是ld-m elf_i386-o exename file.o

所以用这个代替

nasm -f elf test1.asm
ld -m elf_i386 -o test1 test1.o

可能重复您告诉链接器创建64位二进制文件,但您的汇编代码是为32位汇编的。将
-m elf_i386
标志传递给您的链接器。在此处复制
nasm -f elf test1.asm
ld -m elf_i386 -o test1 test1.o