Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2011-12

CPU registers and function calls, unclear explanation in the docs

3 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bernd

The programmer's guide says in chapter 6.3 that when using "register" convention then it does not save any registers. A very old version of this document even said explicitly: "The registers are not saved when calling a function or procedure", this sentence is no longer in the programmer's guide but the table 6.3 still says "None" in the column "registers saved". I interpreted this as "when calling such a function or procedure it [the function] will not save any registers" or in other words If I write such a function myself I can do with eax, edx, ecx, ebx, edi, esi inside my function whatever I want and don't need to save and restore them, the caller is responsible.

But this does not seem to be true. It seems it will assume that at least certain registers are saved by the callee, ebx is one of them I found today by accident because the caller used it as the loop variable and I believe there are other registers too. Or is this "none" meant from the perspective of the callee and means that the *caller* will not save any registers *before* the call? IMHO this section of the manual is a bit vague or ambiguous and could be clarified. (btw. there is also something written about "GCC registers" without mentioning anywhere what a "GCC register" actually is)

Is there maybe any other document somewhere that describes what *exactly* is expected by the compiler to happen with the registers during a function call or maybe somebody can show me where in the FPC sources I have to look to see for myself what exactly is going on?

with exactly I also mean such little details like for example if a function returns QWord then it returns them in eax and edx but if it does only return a DWord then can I still use edx for other things and the caller will just ignore it or will it then be owned by the caller? And what if it is a procedure (no return value at all) who will then own eax?

Bernd

Reply by email

Jonas Maebe
to Bernd
Bernd wrote
Is there maybe any other document somewhere that describes what *exactly* is expected by the compiler to happen with the registers during a function call or maybe somebody can show me where in the FPC sources I have to look to see for myself what exactly is going on?

On i386 with the "register" calling convention,
* eax, ecx and edx are volatile (= caller can overwrite them without saving them)
* ebx, esi, edi, ebp and esp and non-volatile (= caller must save/restore them if it overwrites them)

On other platforms (including x86-64), all calling conventions follow the official platform ABI as far as volatile/non-volatile registers are concerned.

Jonas

Reply by email

Jonas Maebe
to Jonas Maebe
Jonas Maebe wrote 10 lines
On 17 Dec 2011, at 01:46, Bernd wrote: > Is there maybe any other document somewhere that describes what > *exactly* is expected by the compiler to happen with the registers > during a function call or maybe somebody can show me where in the FPC > sources I have to look to see for myself what exactly is going on? On i386 with the "register" calling convention, * eax, ecx and edx are volatile (= caller can overwrite them without saving them) * ebx, esi, edi, ebp and esp and non-volatile (= caller must save/restore them if it overwrites them)

Sorry, caller -> callee

Jonas

Reply by email