c++内联汇编代码,内存访问处的代码,g++编译之后出现问题:
原始代码:
1 int main()
2 {
3 unsigned long tmp = 0;
4 __asm__ __volatile__
5 (
6 ".intel_syntax noprefix\n"
7 "mov rax,%0\n"
8 "mov rbx,1\n"
9 "mov qword [rax],rbx"
10 :
11 :"r"(&tmp)
12 :"rax","rbx"
13 );
14 return 0;
15 }
编译后反汇编代码如下:
0x00000000004004fa <+13>: lea rdx,[rbp-0x10]
0x00000000004004fe <+17>: mov rax,rdx
0x0000000000400501 <+20>: mov rbx,0x1
0x0000000000400508 <+27>: mov QWORD PTR [rax+0x8],rbx
为什么这一句
mov qword [rax],rbx
编译之后变成
mov QWORD PTR [rax+0x8],rbx