0

I saw this sample code in a previous question I asked. I was confused by how the paramaters of int add(int a, int b) were automatically in esi and edi? Is this a default calling convention? Where can I find more of this information.

.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
sigjuice
  • 28,661
  • 12
  • 68
  • 93
jack sexton
  • 1,227
  • 1
  • 9
  • 28

1 Answers1

2

The calling convention of the System V AMD64 ABI is followed on Solaris, Linux, FreeBSD, OS X,[16] and is the de facto standard among Unix and Unix-like operating systems. The first six integer or pointer arguments are passed in registers RDI, RSI, RDX, RCX (R10 in the Linux kernel interface[17]:124), R8, and R9, while XMM0, XMM1, XMM2, XMM3, XMM4, XMM5, XMM6 and XMM7 are used for certain floating point arguments.

Source: https://en.wikipedia.org/wiki/X86_calling_conventions

jack sexton
  • 1,227
  • 1
  • 9
  • 28
  • More specific links to detailed ABI docs in [x86 tag wiki](http://stackoverflow.com/tags/x86/info). There's also a less detailed summary of [x86 calling conventions in SO docs](http://stackoverflow.com/documentation/x86/3261/calling-conventions) – Peter Cordes Sep 14 '16 at 23:02