c - 在汇编中调用符号时函数参数是如何传递的?

标签 c assembly x86

我在上一个问题中看到了这个示例代码。我对 int add(int a, int b) 的参数如何自动出现在 esi 和 edi 中感到困惑?这是默认调用约定吗?我在哪里可以找到更多此类信息。

.globl _add // make it global so that others can find this symbol
....
_add: // int add(int a, int b)
  movl %esi, %eax
  addl %edi, %eax
  ret

最佳答案

System V AMD64 ABI 的调用约定在 Solaris、Linux、FreeBSD、OS X 上得到遵循,[16] 并且是 Unix 和类 Unix 操作系统中的事实标准。前六个整数或指针参数在寄存器 RDI、RSI、RDX、RCX(Linux 内核接口(interface)中的 R10[17]:124)、R8 和 R9 中传递,而 XMM0、XMM1、XMM2、XMM3、XMM4、XMM5、 XMM6 和 XMM7 用于某些浮点参数。

来源:https://en.wikipedia.org/wiki/X86_calling_conventions

关于c - 在汇编中调用符号时函数参数是如何传递的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39437681/

相关文章:

visual-c++ - 编译由 VC++ 生成的程序集输出?

c - Windows C套接字: select() gives WSAENOTSOCK error

c++ - 文字 0 和 0 作为变量如何通过函数 __builtin_clz 产生不同的行为?

linux - 在 Windows 上编译 Linux 汇编器

c - x86 程序集 : Using #define'd constants as arguments in calls to to #define's macros

Cortex-M0+ 定时器预分频器不会减慢 TIM2

c - 两个线程中的同步问题共享一个队列以使用临界区进行读写

c - [C]使用结构体和文件添加、编辑、删除数据

C getchar() 刽子手游戏

c - C 中的内联汇编