ubuntu - 64 位汇编语言在 ubuntu 上使用 nasm

标签 ubuntu assembly 64-bit nasm

我正在尝试用 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/

相关文章:

python - Ubuntu 导入错误 : Could not import settings (works on Mac)

java - 如何修复 Tomcat 应用程序 java.nio.file.AccessDeniedException

linux - NASM中的printf最简单的工作示例失败

linux - 64 位 Linux 上的 dbxtool 无法加载 64 位版本的 dbx?

c++ - WaitForMultipleObjects 在 64 位 Windows 上崩溃

c++ - 64 位构建中 STL/OpenMP 的奇怪并发问题

linux - 像常规命令一样运行脚本

node.js - Linux 上的 NodeJS USB 模块问题

linux - 打开系统调用无法无故创建文件

c - 使用callstack在C中实现栈数据结构?