Calling conventions – System V AMD64 vs. Microsoft x64

General
Calling conventions specify the low-level details for function calls. They are a part of an ABI.


Comparison

System V AMD64 Microsoft x64
Arguments
  • Amount: 6 Integer + 8 Float
  • Integer: 1. RDI, 2. RSI, 3. RDX, 4. RCX, 5. R8, 6. R9
  • Float: XMM0 – XMM7 (1.-8.)
  • Amount: 4 (Integer/Float)
  • Integer/Float: 1. RCX/XMM0, 2. RDX/XMM1, 3. R8/XMM2, 4. R9/XMM3
Return
  • Integer: RAX
  • Float: XMM0
Caller-saved (volatile) RAX, RCX, RDX, RSI, RDI, R8 – R11 RAX, RCX, RDX, R8 – R11
Callee-saved (nonvolatile) RBX, R12–R15, RBP, RSP RBX, RSI, RDI, R12–R15, RBP, RSP

System V AMD64

void func(
    int a, int b, int c,       // a in RDI, b in RSI, c in RDX
    float d, float e, float f, // d in XMM0, e in XMM1, f in XMM2
    int g, int h, int i,       // g in RCX, h in R8, i in R9
    float j, float k, float l, // j in XMM3, k in XMM4, l in XMM5
    float m, float n);         // m in XMM6, n in XMM7
// The next integer or float args would be added to the stack.

Microsoft x64

void func(int a, float b, int c, float d, int e);
// a in RCX, b in XMM1, c in R8, d in XMM3
// The next integer or float args would be added to the stack.

Details
In C++ classes, the “this” pointer is the first argument.