2

enter image description here

Why does godbolt (gcc 9.3) show parameter being passed in edi if C++ uses cdecl calling convention? I can't find anything on this

1 Answers1

9

RBP and RSP are 64-bit registers, which means your code is being compiled for 64-bit, not 32-bit. cdecl is a 32-bit calling convention, it simply does not exist in 64-bit. On 64-bit systems, the first few integer-sized parameters are passed via registers, not the call stack.

On non-Windows platforms (godbolt runs on Amazon EC2 instances using Ubuntu), the first 6 integer-sized parameters are passed via the RDI, RSI, RDX, RCX, R8, and R9 registers, respectively. EDI is bytes 0-3 of RDI, and int is 4 bytes in your compiler, so you see the num parameter being passed via EDI.

On Windows platforms, the first 4 integer-sized parameters are passed via the RCX, RDX, R8, and R9 registers, respectively. EDI is not used for passing parameters.

See Stack frame layout on x86-64 for more details.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Probably should have seen this as well https://learn.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2019 –  Apr 01 '20 at 02:30
  • @JohnBap I did see that, actually. But I didn't mention it since godbolt doesn't run on Windows, and also because the doc I did link to in my answer links to the MSDN docs. – Remy Lebeau Apr 01 '20 at 05:35