我正在尝试用 64 位汇编编写一个简单的 hello world 程序并在 Ubuntu 64 位上运行。程序如下:
global _start ; entry point export for ld section .text
_start: ; system call to write message to stdout
mov rax, 1 ; sys_write
mov rdi, 1 ; stdout
mov rsi, mes ; message address
mov rdx, len ; message length
syscall ; exit sys call
mov rax, 60 ; exit call id
mov rdi, 0 ; return success
syscall
section .data
mes: db 'Hello, world!',0x0A ; message
len : equ $-mes
我使用 nasm -f elf64 hello64.asm
组装了它
并尝试使用 ld -o hello64 hello64.o
链接它
它给了我以下错误 -
ld: i386:x86-64 architecture of input file `hello64.o' is incompatible with i386 output
即使使用标志 --oformat elf64-x86-64 或 elf64-little 或 elf64-big,我也会遇到同样的错误。
有人可以帮忙吗?
最佳答案
以下适用于我的系统:
nasm -f elf64 hello64.asm
ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o hello64 hello64.o
关于ubuntu - 64 位汇编语言在 ubuntu 上使用 nasm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20935447/