Which registers are safe for use in a function (x86)

According to Wikipedia , Intel ABI allows the use of EAX , ECX and EDX without storing them in a function.
I'm not sure what Intel ABI means. Does this mean that it is forced / followed by all compilers targeting Intel processors? I am writing a build function that will be called from C code. Can I count this for all compilers? (I am only targeting x86 at the moment)

+8
assembly x86 abi
source share
2 answers

Intel ABI is simply a call agreement established by Intel.

In general, how parameters are transferred and which registers are saved or deactivated during a function call is determined by the function call agreement:

http://en.wikipedia.org/wiki/Calling_convention

In particular, for __cdecl, __stdcall and __fastcall you should expect that EAX, ECX and EDX will be broken, and your function should save other registers and return to EAX (or EDX: EAX for 64-bit returns).

If you do not know which calling convention you should use, you should not write in the assembly, since entering the calling convention may lead to errors in your application.

In C, the standard calling convention is usually __cdecl, and for exported Windows APIs, usually __stdcall.

+6
source share

This is the binary interface of the Intel application, a set of rules that dictates things such as which registers are available for use, without saving, how arguments are pushed onto the stack, regardless of whether the calling or called cells clear the stack frames, etc.

If you know that the rules are being followed, that's fine. I try to save everything just in case (except for the things that I use to return information, of course).

But this does not necessarily apply to all compilers, and you would not be wise to think about it, unless the compiler makes a reservation about it.

+1
source share

All Articles