x86 gcc compiled assembly code: fastcall behavior

1.2k Views Asked by At

I am working on some x86 assembly program analysis tasks, and I am trying to figure out the fastcall behavior.

Although on 32-bit x86 platform, the stack is defined to pass the function parameters in the calling conversion. However, I observed that many function calls are indeed leveraging two registers, eax and edx to pass the first two function parameters.

For example, here is a (simplified) example found in libgcrypt 1.6.1:

  mov  0x24(%esp), %eax
  ...
  mov  0x1c(%esp), %edx
  call mul_n
  ...
mul_n:
  ...
  mov  %eax, 0x20(%esp)
  mov  %edx, 0x24(%esp)

As you can see, register eax and edx are used to pass parameters. My observation is that those two registers are always used to pass the first two parameters.

Note that I am using gcc to compile the code. However, I can only find the fastcall definition of the Microsoft compiler, which uses register ecx (not eax!) and edx to pass parameters.

So here is my question: is there any clear definition of such gcc optimization? I just cannot find some informative sources...

0

There are 0 best solutions below