【发布时间】:2011-05-14 05:26:06
【问题描述】:
我正在使用 ubuntu 64 位并尝试在 NASM 上运行 .asm 文件。但是当我尝试运行以下代码时它会返回此错误。我试图做的是通过从源代码编译(或组装)目标文件来构建可执行文件
$ nasm -f elf hello.asm,然后在创建文件后,hello.o 通过调用链接器从目标文件生成可执行文件本身
$ ld -s -o hello hello.o
这将最终构建 hello 可执行文件。
我正在关注这个教程http://www.faqs.org/docs/Linux-HOWTO/Assembly-HOWTO.html
错误:
输入文件 `hello.o' 的 i386 架构与 i386:x86-64 输出不兼容
代码:
section .data ;section declaration
msg db "Hello, world!",0xa ;our dear string
len equ $ - msg ;length of our dear string
section .text ;section declaration
;we must export the entry point to the ELF linker or
global _start ;loader. They conventionally recognize _start as their
;entry point. Use ld -e foo to override the default.
_start:
;write our string to stdout
mov edx,len ;third argument: message length
mov ecx,msg ;second argument: pointer to message to write
mov ebx,1 ;first argument: file handle (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
;and exit
mov ebx,0 ;first syscall argument: exit code
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
【问题讨论】:
标签: linux ubuntu nasm assembly