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
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.