All parameters are passed to functions on the software stack. They are stacked in reverse order (1st parameter pushed last)7. Moreover, the stack cleaning is performed by caller : these characteristics are common for C code because they are useful to implement functions with variable number of parameters, such as printf8.
8 bit results are returned in _r0L
register, 16 bit results are returned in _r0
register and 32 bit results are returned in the _r0-_r1 pair.
Structures are returned in a block of memory that begins at address _r0, with the same size than the returned structure. Enough space is reserved by default for structure up to 40 bytes. This pool can adjusted to fit you needs or the hardware requirements. See section 11.2 for details.
Here is a call of the previous function h(int u, int v):
void caller() { int res, k ; res = h(k, 25) ; }
and the resulting code
C18_caller movf PREINC0,F,0 ; reserve stack space movf PREINC0,F,0 ; for k and res movlw 25 movwf PREINC0,0 ; push param 25 onto the stack movlw -1 movff PLUSW0,PREINC0 ; push parameter k ICALL C18_h ; call h() movf POSTDEC0,F,0 ; (partially) clean stack movff _r0,INDF0 ; move result to temporary movlw -1 ; pop result to res and movff POSTDEC0,PLUSW0 ; finish to clean stack movf POSTDEC0,F,0 movf POSTDEC0,F,0 ; (discard local variables) return 0