Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 如何理解AT&;TI386汇编代码片段?_Assembly_32 Bit_Att_I386 - Fatal编程技术网

Assembly 如何理解AT&;TI386汇编代码片段?

Assembly 如何理解AT&;TI386汇编代码片段?,assembly,32-bit,att,i386,Assembly,32 Bit,Att,I386,请查看以下代码段: int和sum(int和num1,int和num2){ num1++; num2++; } 00000000: 0:55推力%ebp 1:89 e5 mov%esp,%ebp 3:e8 fc ff呼叫4//为什么这里有跳转 8:05 01 00添加$0x1,%eax //为什么是0x8,我的理解是总共有3个参数 //num2--0xc(%ebp),num1--0x8(%ebp),this--0x4(%ebp) //我说的对吗???? d:8b 45 08 mov 0x8(%

请查看以下代码段:

int和sum(int和num1,int和num2){
num1++;
num2++;
}
00000000:
0:55推力%ebp
1:89 e5 mov%esp,%ebp
3:e8 fc ff呼叫4//为什么这里有跳转
8:05 01 00添加$0x1,%eax
//为什么是0x8,我的理解是总共有3个参数
//num2--0xc(%ebp),num1--0x8(%ebp),this--0x4(%ebp)
//我说的对吗????
d:8b 45 08 mov 0x8(%ebp),%eax
10:80亿mov(%eax),%eax
12:8d50 01 lea0x1(%eax),%edx//这到底是什么?
15:8b 45 08 mov 0x8(%ebp),%eax
18:89 10 mov%edx,(%eax)
1a:8b 45 0c mov 0xc(%ebp),%eax
1d:8b 00 mov(%eax),%eax
1f:8d 50 01 lea 0x1(%eax),%edx
22:8b 45 0c mov 0xc(%ebp),%eax
25:89 10 mov%edx,(%eax)
27:90不
28:5d流行百分比ebp
29:c3 ret
我需要弄清楚每一行的意思,有点让我困惑

   3:   e8 fc ff ff ff          call   4 <_Z3sumRiS_+0x4>
对于其余的说明,这里是一个逐步分析

// as num1 and num2 are references, they represents address in assembly
   d:   8b 45 08                mov    0x8(%ebp),%eax        // load num1 to %eax
  10:   8b 00                   mov    (%eax),%eax           // load *num1 to %eax
  12:   8d 50 01                lea    0x1(%eax),%edx        // put *num1 + 1 into %edx
  15:   8b 45 08                mov    0x8(%ebp),%eax        // load num1 to %eax
  18:   89 10                   mov    %edx,(%eax)           // save *num1 + 1 at num1
  1a:   8b 45 0c                mov    0xc(%ebp),%eax        // same as above
  1d:   8b 00                   mov    (%eax),%eax
  1f:   8d 50 01                lea    0x1(%eax),%edx
  22:   8b 45 0c                mov    0xc(%ebp),%eax
  25:   89 10                   mov    %edx,(%eax)

这不是C++成员函数,所以没有<代码>这个< /C> >参数。保存的EBP上方的堆栈插槽是返回地址。此外,它还有未定义的行为,因为您从非
void
函数的末尾掉下来。GCC
-O0
似乎是故意在返回值寄存器中计算最后一个表达式的副作用,因此如果您只关心
GCC-O0
。它完全被破坏了。“彼得科尔德是一个C++代码。我把它当作一种体验。故意没有返回值。至于
这到底是什么?
lea0x1(%eax),%edx
加载
eax
指向的值,添加一个,然后将结果存储在
edx
中。这是你的
num1++-接下来的存储到内存完成了它。查看具有未定义行为的代码的编译器输出可能会令人困惑,我不建议您首先使用它。请参阅-可以将源代码行与asm块匹配。此外,
调用
/
添加
是因为这是一个32位饼图,禁用优化后,GCC将生成代码以获取指向GOT的指针。您正在查看对
.o
的反汇编,因此链接器尚未填充偏移量。使用
objdump-drwC
(最好使用
-Mintel
,除非您确实喜欢AT&T语法)。或者更好的方法是查看编译器asm输出,而不是从二进制文件反汇编。
0xc  |      num2      |
0x8  |      num1      |
0x4  | return address |
0x0  | previous %ebp  |  <-- %ebp
// as num1 and num2 are references, they represents address in assembly
   d:   8b 45 08                mov    0x8(%ebp),%eax        // load num1 to %eax
  10:   8b 00                   mov    (%eax),%eax           // load *num1 to %eax
  12:   8d 50 01                lea    0x1(%eax),%edx        // put *num1 + 1 into %edx
  15:   8b 45 08                mov    0x8(%ebp),%eax        // load num1 to %eax
  18:   89 10                   mov    %edx,(%eax)           // save *num1 + 1 at num1
  1a:   8b 45 0c                mov    0xc(%ebp),%eax        // same as above
  1d:   8b 00                   mov    (%eax),%eax
  1f:   8d 50 01                lea    0x1(%eax),%edx
  22:   8b 45 0c                mov    0xc(%ebp),%eax
  25:   89 10                   mov    %edx,(%eax)