

Common x86 Calling Conventions - mirceasoaica
https://jlospinoso.github.io/assembly/c/developing/software/2015/04/04/common-x86-calling-conventions.html

======
vardump
Title should be "Microsoft x86 Calling Conventions". The whole article is
based on Microsoft-specific conventions and tools.

When I saw the following, I stopped reading:

    
    
      MultiplyEaxByTwo:
      shl eax,2
      ret
    

"shl eax, 2" means bit shift left eax by two, or "eax << 2". Also, while the
end result is same as with "shl" [1], "sal" [2] should be used for idiomatic
[3] assembler:

Fixed:

    
    
      CorrectMultiplyEaxByTwo:
      sal eax, 1
      ret
    

[1]: "shl", shift logical left

[2]: "sal", shift arithmetic left

[3]:
[http://en.wikibooks.org/wiki/X86_Assembly/Shift_and_Rotate#A...](http://en.wikibooks.org/wiki/X86_Assembly/Shift_and_Rotate#Arithmetic_Shift_Instructions)

~~~
rurban
And 32 bit only. It doesn't cover the 64bit conventions which deviates more
wildly on Win64 from the common amd64 ABI.

~~~
masklinn
Talking about 64b, does anyone know _why_ MS decided not to go with the AMD64
abi? Is it because they had their own 64bit CC for e.g. itanium and kept that?

~~~
0x0
Looks like they went with extending their existing __fastcall calling
convention.
[http://blogs.msdn.com/b/oldnewthing/archive/2004/01/02/47184...](http://blogs.msdn.com/b/oldnewthing/archive/2004/01/02/47184.aspx)

------
0xFFC
Can you introduce good books about these topics?(linker,loader,calling
conventions ,dynamic linking etc).I am looking for good book for deeply
understanding these topics(given that traditional OS books just talks about
theory)

~~~
mdaniel
I can't comment on its "goodness" but the textbook that sprang to mind is
Linkers and Loaders: [http://www.amazon.com/Linkers-Kaufmann-Software-
Engineering-...](http://www.amazon.com/Linkers-Kaufmann-Software-Engineering-
Programming/dp/1558604960)

The bad news is that it's from '99 but, as far as the foundations go, I can't
imagine linkers back then were _that_ different.

------
revelation
Thank god for x64 that got rid of this unnecessary cruft.

~~~
cremno
A wild __vectorcall appeared!

[http://blogs.msdn.com/b/vcblog/archive/2013/07/12/introducin...](http://blogs.msdn.com/b/vcblog/archive/2013/07/12/introducing-
vector-calling-convention.aspx)

[https://msdn.microsoft.com/en-
us/library/dn375768.aspx](https://msdn.microsoft.com/en-
us/library/dn375768.aspx)

