Calling conventions
+
+There are two calling conventions used in cc65:
+
+
+ -
+
- A/X/sreg and all others on the C-stack.
+
+
+
+The default convention is Prologue, before the function call
+
+If the function is declared as fastcall, the rightmost argument will be loaded into
+the A/X/sreg registers:
+
+
+ -
+
-
+
-
+
+
+All other parameters will be pushed to the C-stack from left to right.
+The rightmost parameter will have the lowest address on the stack,
+and multi-byte parameters will have their least significant byte at the lower address.
+
+The
+// C prototype
+void cdecl foo(unsigned bar, unsigned char baz);
+
+; C-stack layout within the function:
+;
+; +------------------+
+; | High byte of bar |
+; Offset 2 ->+------------------+
+; | Low byte of bar |
+; Offset 1 ->+------------------+
+; | baz |
+; Offset 0 ->+------------------+
+
+; Example code for accessing bar. The variable is in A/X after this code snippet:
+;
+ ldy #2 ; Offset of high byte of bar
+ lda (sp),y ; High byte now in A
+ tax ; High byte now in X
+ dey ; Offset of low byte of bar
+ lda (sp),y ; Low byte now in A
+
+
+Epilogue, after the function call
+
+Return requirements
+
+If the function has a return value, it will appear in the A/X/sreg registers.
+
+Functions with an 8-bit return value (A/X/sreg, so these may be clobbered by the function.
+
+The C-stack pointer Clobbered state
+
+The A/X/sreg registers may be clobbered if any of them
+are not used by the return value (see above).
+
+Many of the internal pseudo-registers used by cc65 are available for
+free use by any function called by C, and do not need to be preserved.
+Note that if another C function is called from your assembly function,
+it may clobber any of these itself:
+
+
+ - tmp1 .. tmp4
+ - ptr1 .. ptr4
+ - regsave
+ - sreg (if unused by return)
+
+
+
+
+