我正在阅读 这篇 文章,
其中有一段给出了以下 nasm 程序:
我得到了以下错误:
我猜测可能存在问题,并将BITS行更改为以下内容:
另一方面,
; tiny.asm
BITS 32
GLOBAL main
SECTION .text
main:
mov eax, 42
ret
并告诉我运行以下命令:
$ nasm -f elf tiny.asm
$ gcc -Wall -s tiny.o
我得到了以下错误:
ld: warning: option -s is obsolete and being ignored
ld: warning: ignoring file tiny.o, file was built for unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
我猜测可能存在问题,并将BITS行更改为以下内容:
BITS 64
但是,当我运行nasm -f elf tiny.asm
时,会出现以下内容:
tiny.asm:2: error: `64' is not a valid segment size; must be 16 or 32
如何修改代码以使其在我的机器上运行?
编辑:
我采纳了评论中Alex的建议并下载了更新版本。然而,
./nasm-2.09.10/nasm -f elf tiny.asm
投诉
tiny.asm:2: error: elf32 output format does not support 64-bit code
另一方面,
./nasm-2.09.10/nasm -f elf64 tiny.asm
gcc -Wall -s tiny.o
投诉
ld: warning: ignoring file tiny.o, file was built for unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status