## Function calling conventions

All parameters are passed to functions on the software stack. They are stacked in reverse order (1st parameter pushed last)6. 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 `printf` 7.

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 10.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

#### Footnotes

... last)6
  No alignment is done during parameter passing, so data can be located at odd or even address.
...`printf` 7
  This feature will change in future versions.