我正在阅读http://www.ibm.com/developerworks/linux/library/l-gas-nasm/index.html上的一些教程,以熟悉 x86/x64。本教程代码使用所提供的代码(使用 AT&T 语法)编译和运行时不会出现问题:
.global main
.text
main: # This is called by C library's startup code
mov $message, %rdi # First integer (or pointer) parameter in %edi
call puts # puts("Hello, World")
ret # Return to C library code
message:
.asciz "Hello, World" # asciz puts a 0x00 byte at the end
但是,当我将此代码转换为 Intel 语法时,我收到“分段错误”错误。
.intel_syntax noprefix
.global main
.text
main: # This is called by C library's startup code
mov rdi, message # First integer (or pointer) parameter in %edi
call puts # puts("Hello, World")
ret # Return to C library code
message:
.asciz "Hello, World" # asciz puts a 0x00 byte at the end
我不熟悉 x86,所以也许我遗漏了一些东西。有任何想法吗?