问题描述
我通过一些教程上的http://www.ibm.com/developerworks/linux/library/l-gas-nasm/index.html以自己熟悉的x86 / x64操作系统。本教程code编译和使用提供code,它使用AT&功放没有打嗝运行; T语法:
I'm working through some of the tutorials on http://www.ibm.com/developerworks/linux/library/l-gas-nasm/index.html to familiarize myself with x86/x64. This tutorial code compiles and runs without a hiccup using the provided code, which uses AT&T syntax:
.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
然而,当我转换这个code到Intel语法,我得到一个分段错误错误。
However, when I convert this code to Intel syntax, I get a "Segmentation fault" error.
.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,所以也许我失去了一些东西。任何想法?
I'm not familiar with x86, so perhaps I'm missing something. Any ideas?
推荐答案
在AT& T公司的语法, MOV $消息,%RDI
的 $
手段的直接的,这意味着地址的的消息的
In AT&T syntax, mov $message, %rdi
, the $
means immediate, meaning the address of message.
在GAS的Intel语法, MOV RDI,消息
表示绝对寻址,在的消息的意思是内容即可。要获得的的消息的,您需要提供偏移
关键字的实际地址: MOV RDI,偏移信息
。
In GAS's Intel syntax, mov rdi, message
means absolute addressing, meaning the content at message. To get the actual address of message, you need to supply the offset
keyword: mov rdi, offset message
.
两个二进制Disassebly显示区别:
Disassebly of the two binaries shows the difference:
AT& T公司:
AT&T:
0000000000000000 <main>:
0: 48 c7 c7 00 00 00 00 mov $0x0,%rdi
英特尔:
0000000000000000 <main>:
0: 48 8b 3c 25 00 00 00 mov 0x0,%rdi
这篇关于为什么从AT&放不切换;吨至Intel语法使本教程中使用段错误GAS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!