4.3.3 Calling convention

By default, all parameters are passed on the stack, right-to-left. 8-bit return values are passed in l, 16-bit values in hl, 32-bit values in dehl. Except for the GBZ80, where 8-bit values are passed in e, 16-bit values in de, 32-bit values in hlde. Larger return values are passed in memory in a location specified by the caller through a hidden pointer argument.

There are three other calling conventions supported, which can be specified using the keywords __smallc, __z88dk_fastcall (not on GBZ80) and __z88dk_callee. They are primarily intended for compability with libraries written for other compilers. For __smallc, the parameters are passed on the stack, left-to-right, but variable arguments are currently not supported. For __z88dk_fastcall, there may be only one parameter of at most 32 bits, which is passed the same way as the return value. For __z88dk_callee, parameters are passed on the stack, but the stack is not adjusted for the parameters after the call (thus the callee has to do this instead). __z88dk_callee is currently supported on the caller side only. __z88dk_callee can be combined with __smallc.