pradeep wrote:
We know that a C function will return a 32-bit value from a function
in %eax and a 64-bit value in %edx:%eax.
In some x86 implementations , yes. But the ARM has no %eax or
%edx and yet manages to return results. But generalising ...
But what about larger return
types, for example large structs? The only other spare register is
%ecx because %ebx needs to be preserved, but that only brings the
%possible total up to 96 bits. What happens after that?
One tactic is:
The return type of the function is known. So the compiler can
allocate an object of that type in the callING function and
pass its address to the callED function as an additional hidden
argument; the callED function writes its result into that
object using the pointer argument. Then when control returns
to the callING function the compiler can arrange for code to
copy the value of the allocated object to its final destination.
A sufficiently clever compiler given sufficiently simple code
may be able to eliminate the copy by passing the address of the
final destination.
"Every programming problem can be solved by adding an additional
layer of indirection".
--
"Give as few orders as possible. Once you have given orders /Dune/
on a subject, you must always give orders on that subject."
Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England