That would add extra code and extra memory writes to every single function call. It may not seem significant now, but back in the 80's when this convention was created it probably did matter.
Up vote -1 down vote favorite 1 share g+ share fb share tw.
IA-32 calling convention says: • Callee-save registers %ebx, %esi, %edi Callee must not change these. If it changes it must restore to old values. • Caller-save registers %eax, %edx, %ecx Caller saves these if it wants to preserve them.
Why does this strange convention exist? Why not save all the register before calling another function? Assembly ia-32 link|improve this question asked Dec 1 '11 at 1:45Bruce2,041940 87% accept rate.
That would add extra code and extra memory writes to every single function call. It may not seem significant now, but back in the 80's when this convention was created it probably did matter. And note that ia-32 doesn't have a fixed calling convention - what you list is only an external convention - ia-32 doesn't enforce it.
If you're writing your own code you use the registers however you wish. Also see the discussion History of Calling Conventions at the Old New Thing Blog. When deciding which registers should be preserved by a calling convention, you need to balance the needs of the caller against the needs of the callee.
The caller would prefer that all registers be preserved, since that removes the need for the caller to worry about saving/restoring the value across a call. The callee would prefer that no registers be preserved, since that removes the need to save the value on entry and restore it on exit. If you require too few registers to be preserved, then callers become filled with register save/restore code.
But if you require too many registers to be preserved, then callees become obligated to save and restore registers that the caller might not have really cared about. This is particularly important for leaf functions (functions that do not call any other functions).
A guess: If the caller saves all registers it will still need after a function call, it wastes time when the called function doesn't modify all those registers. If the callee saves all registers it changes, it wastes time when the caller didn't need the values in those registers again. When some registers are saved by caller and some by callee, the compiler (or assembly programmer) can choose which kind to use depending on if the value is needed after the next function call.
If you look a little deeper into the registers used, you can see why they won't be preserved by the callee: EAX: used for function returns, so quite obviously it cannot be preserved. EDX:EAX: used for 64bit function returns, same as EAX. ECX: this is the count register, and back in the older days of x86 when LOOPcc was 'cool', this register would be thrashed like mad, even today there are still quite a few instructions using ECX as a counter (like REP prefixed instructions).
However, thanks to the advent of __thiscall and __fastcall, it gets used to pass args in, which means its very likely to change, so there is almost not point in preserving it. ESP: this is a little side exception, as its not really preserved, its altered in accordance with stack changes. Though it can be preserved to prevent stack pointer corruption/security or unbalancing thanks to inline assembly (via stack frames).
Now it actually becomes intuitive :).
– Bruce Dec 1 '11 at 9:53 @Bruce: so that it can be called by anything, ie: the caller need not know anything about the internals of the callee, as the callers data will be preserved (ESI & EDI are the data src/dest registers, so this keeps in line with separating the caller data from the callee). – Necrolis Dec 1 '11 at 10:59.
In short, caller save are because of argument passing. Everything else is callee save.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.