The Z80 and 6502 are both 8-bit microprocessors that were widely used in various computing systems, including early personal computers, game consoles, and embedded systems. Because they were used in a wide range of systems, there was no single standard calling convention across all platforms based on these CPUs. Instead, calling conventions could vary depending on the operating system, the language/runtime environment in use, and the conventions adopted by individual software developers or teams.
However, there are some general practices that were commonly used:
Z80 Calling Conventions:
The Z80 processor has a more sophisticated set of instructions and addressing modes than the 6502, as well as more registers, allowing for more flexibility in designing calling conventions. A typical calling convention for Z80-based systems might involve:
- Passing parameters in registers where possible, for faster access.
- Using the stack to store additional parameters, return addresses, and local variables.
- Employing the
CALL and RET instructions for subroutine calls and returns.
- Preserving the contents of some registers (usually the alternate set,
AF', BC', DE', and HL') across calls, treating them as callee-saved. Some calling conventions might require the caller to save these if they want to preserve their values.
The specifics would be influenced by the size of the data, the available registers, and the conventions of the particular system or software.
6502 Calling Conventions:
The 6502 has a more limited set of registers (Accumulator, X index, Y index, and Stack Pointer), which influenced its calling conventions:
- Passing parameters in registers for quick access when possible, often using the Accumulator for single-byte values or return values.
- Using the stack to pass additional arguments or to store local variables and return addresses. This typically involved manually pushing and pulling bytes onto the stack, as the 6502 does not have direct push/pop instructions for general-purpose registers.
- Using the
JSR (Jump to SubRoutine) instruction to call functions, and RTS (ReTurn from Subroutine) for returning.
- Frequently, the caller would be responsible for saving and restoring register state if necessary, given the limited number of registers and the common use of the Accumulator for return values.
Developers on both systems often had to optimize their calling conventions for space and speed, as memory and processing power were quite limited on these early microprocessor systems. The use of zero page (on 6502-based systems) or certain fixed memory locations (often seen on Z80-based systems) to store frequently used variables or to pass parameters is another example of such optimization.
In summary, while there was no absolute standard calling convention for Z80 and 6502 based systems, certain patterns and practices were common, although they varied based on the specific requirements and constraints of the systems and software in question.