Compiled Stack Return Values

For functions that use the compiled stack, return values are passed to the calling function using the W register, or the function’s parameter memory. The memory assigned to the function’s parameters (which is no longer needed when the function is ready to return) is reused to reduce the function’s code and data requirements.

Single-byte values are returned from a function in the W register. Values larger than a byte are returned in the function’s parameter memory area.

For example, the function:

int returnWord(void)
{
    return 0x1234;
}

will return with the value 0x34 in ?_returnWord, and 0x12 in ?_returnWord+1.

For PIC18 targets returning values greater than 4 bytes but less than 8 bytes in size, the address of the parameter area is also placed in the FSR0 register.

Functions that return a value of type __bit do so using the carry bit in the STATUS register.