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 反汇编简单码的结构问题_Assembly_X86 - Fatal编程技术网

Assembly 反汇编简单码的结构问题

Assembly 反汇编简单码的结构问题,assembly,x86,Assembly,X86,我在英特尔赛扬上使用Ubuntu 20.04 我反汇编了这个C代码 extern int addintandint(int i,int j) { return i + j; } 像这样 $ gcc -c addintandint.c $ objdump -d addintandint.o > dump.txt 结果就是这样 addintandint.o: file format elf64-x86-64 Disassembly of section .text:

我在英特尔赛扬上使用Ubuntu 20.04 我反汇编了这个C代码

extern int addintandint(int i,int j)
{
    return i + j;
}
像这样

$ gcc -c addintandint.c
$ objdump -d addintandint.o > dump.txt
结果就是这样


addintandint.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <addintandint>:
   0:   f3 0f 1e fa             endbr64 
   4:   55                      push   %rbp
   5:   48 89 e5                mov    %rsp,%rbp
   8:   89 7d fc                mov    %edi,-0x4(%rbp)
   b:   89 75 f8                mov    %esi,-0x8(%rbp)
   e:   8b 55 fc                mov    -0x4(%rbp),%edx
  11:   8b 45 f8                mov    -0x8(%rbp),%eax
  14:   01 d0                   add    %edx,%eax
  16:   5d                      pop    %rbp
  17:   c3                      retq 

addintandint.o:文件格式elf64-x86-64
第节的分解。正文:
0000000000000000 :
0:f3 0f 1e fa endbr64
4:55%rbp
5:48 89 e5 mov%rsp,%rbp
8:89 7d fc mov%edi,-0x4(%rbp)
b:89 75 f8移动%esi,-0x8(%rbp)
e:8b 55 fc mov-0x4(%rbp),%edx
11:8b 45 f8 mov-0x8(%rbp),%eax
14:01 d0添加%edx,%eax
16:5d流行百分比rbp
17:c3 retq
我可以通过添加%edx、%eax来理解,我们添加了I和j,但其余的数据操作我无法理解

例如,%edx和%eax I无法跟踪输入数据流

添加后%edx去了哪里? 有人能教我吗

  • 按下堆栈基指针以保存上一个堆栈
  • 按堆栈顶部指针设置堆栈底部指针,因此它现在是一个帧指针。堆栈初始化已完成
  • edi
    esi
    寄存器复制到堆栈中。(它们由调用方设置。它们是函数参数变量)
  • 读取步骤3复制的堆栈。请注意,
    eax
    寄存器用于存储此函数的返回值
  • 请注意,此存储/重新加载是一种调试模式。一个普通的优化构建会简单得多

    mov    -0x4(%rbp),%edx
    mov    -0x8(%rbp),%eax
    
  • 添加操作。结果将在
    eax
    寄存器中设置
  • 恢复堆栈
  • 跳回呼叫方

  • 使用gcc-O2获得可读的程序集输出。否则,gcc会生成如此糟糕的代码,以至于很难看到它在做什么。它不叫“cdecl”。如果您需要它的名称,请使用“sysv”,如GCC的
    \uuuuu attribute\uuuu((sysv\u abi))
    中所述,以表示调用约定。@Peter Cordes感谢您的编辑和评论!
    mov    %rsp,%rbp
    
    mov    %edi,-0x4(%rbp)
    mov    %esi,-0x8(%rbp)
    
    mov    -0x4(%rbp),%edx
    mov    -0x8(%rbp),%eax
    
    add    %edx,%eax
    
    pop    %rbp
    
    retq