A called function (child function) must perform the following tasks:
You must be careful to properly declare functions that accept structure arguments, both at the point where they are called (so that the structure argument is passed as an address) and at the point where they are declared (so the function knows to copy the structure to a local copy).
16-bit integer value | AL | ||
32-bit integer value | ACC | ||
64-bit integer value | ACC/P | ||
32-bit pointer | XAR4 | ||
structure reference | XAR6 |
If the target is FPU and a 32-bit float value is returned, the called function places this value in R0H.
If the function returns a structure, the caller allocates space for the structure and passes the address of the return space to the called function in XAR6. To return a structure, the called function copies the structure to the memory block pointed by the extra argument.
In this way, the caller can be smart about telling the called function where to return the structure. For example, in the statement s= f(x), where S is a structure and F is a function that returns a structure, the caller can actually make the call as f(&s, x). The function f then copies the return structure directly into s, performing the assignment automatically.
If the caller does not use the return structure value, an address value of 0 can be passed as the first argument. This directs the called function not to copy the return structure.
You must be careful to properly declare functions that return structures both at the point where they are called (so that the extra argument is passed) and at the point where they are declared (so the function knows to copy the result). Returning 64-bit floating-point values (long double) are returned similarly to structures.