2019-07-15 12:21:50 +00:00
|
|
|
[< back to index](../doc_index.md)
|
2018-07-03 21:28:05 +00:00
|
|
|
|
|
|
|
# Millfork calling convention
|
|
|
|
|
|
|
|
**Note:** all the info below may change without any warning and is given only for debugging purposes.
|
|
|
|
|
|
|
|
## 6502
|
|
|
|
|
|
|
|
#### Parameters:
|
|
|
|
|
|
|
|
* if the function has one parameter of size one byte, it is passed via the A register
|
|
|
|
|
|
|
|
* otherwise, all parameters are passed via static locations
|
|
|
|
|
|
|
|
#### Return values:
|
|
|
|
|
|
|
|
* one-byte return values are passed via the A register
|
|
|
|
|
|
|
|
* two-byte return values are passed via the A (low byte) and X (high byte) register
|
|
|
|
|
2018-07-30 12:33:16 +00:00
|
|
|
* otherwise, the return value is passed via a static location
|
|
|
|
|
2018-07-03 21:28:05 +00:00
|
|
|
#### Register preservation:
|
|
|
|
|
|
|
|
* callee may clobber all three registers (A, X, Y) and most flags (Z, V, C, N, and also I if using inline assembly)
|
|
|
|
|
|
|
|
* callee expects the D flag to be clear and will leave it clear
|
|
|
|
|
|
|
|
* on 65816: callee will preserve the emulation flag
|
|
|
|
(setting the emulation flag correctly is the responsibility of the initialization code)
|
|
|
|
|
|
|
|
* on 65816 in native mode:
|
|
|
|
|
|
|
|
* callee expects the M and X flag to be set and will leave them set
|
|
|
|
(8-bit accumulator and index registers by default)
|
|
|
|
|
|
|
|
* callee expects the direct page register to be set to 0000 and will not change it
|
|
|
|
|
|
|
|
## Z80
|
|
|
|
|
|
|
|
#### Parameters:
|
|
|
|
|
2018-07-23 23:43:59 +00:00
|
|
|
* if the function has one parameter of size one byte, it is passed via the A register
|
|
|
|
|
|
|
|
* if the function has one parameter of size two bytes, it is passed via the HL register pair
|
|
|
|
|
2018-07-30 12:33:16 +00:00
|
|
|
* if the function has one parameter of size three bytes,
|
|
|
|
its least significant two bytes are passed via the HL register pair
|
|
|
|
and the most significant byte is passed via the E register
|
|
|
|
|
|
|
|
* if the function has one parameter of size four bytes,
|
|
|
|
its least significant word is passed via the HL register pair
|
|
|
|
and the most significant word is passed via the DE register pair
|
|
|
|
|
2018-07-23 23:43:59 +00:00
|
|
|
* otherwise, all parameters are passed via static locations
|
2018-07-03 21:28:05 +00:00
|
|
|
|
|
|
|
#### Return values:
|
|
|
|
|
|
|
|
* one-byte return values are passed via the A register
|
|
|
|
|
|
|
|
* two-byte return values are passed via the HL register pair
|
|
|
|
|
2018-07-30 12:33:16 +00:00
|
|
|
* in case of three-byte return values,
|
|
|
|
its least significant two bytes are passed via the HL register pair
|
|
|
|
and the most significant byte is passed via the E register
|
|
|
|
|
|
|
|
* in case of four-byte return values,
|
|
|
|
its least significant word is passed via the HL register pair
|
|
|
|
and the most significant word is passed via the DE register pair
|
|
|
|
|
|
|
|
* otherwise, the return value is passed via a static location
|
|
|
|
|
2018-07-03 21:28:05 +00:00
|
|
|
#### Register preservation:
|
|
|
|
|
|
|
|
* callee may clobber all flags
|
|
|
|
|
2019-10-22 00:01:18 +00:00
|
|
|
* callee may clobber all registers except for SP, IX, IY and shadow registers
|
2018-07-03 21:28:05 +00:00
|
|
|
|
2019-05-31 15:03:35 +00:00
|
|
|
## 8086
|
|
|
|
|
|
|
|
The Intel 8086 calling conventions is based on the Intel 8080 calling convention,
|
|
|
|
plus it uses the BP register in the same role as the IX register of Z80.
|
2019-06-11 22:20:24 +00:00
|
|
|
The DI register is not used.
|
2019-05-31 15:03:35 +00:00
|
|
|
|
|
|
|
#### Parameters:
|
|
|
|
|
|
|
|
* if the function has one parameter of size one byte, it is passed via the AL register
|
|
|
|
|
|
|
|
* if the function has one parameter of size two bytes, it is passed via the BX register
|
|
|
|
|
|
|
|
* if the function has one parameter of size three bytes,
|
|
|
|
its least significant two bytes are passed via the BX register
|
|
|
|
and the most significant byte is passed via the DL register
|
|
|
|
|
|
|
|
* if the function has one parameter of size four bytes,
|
|
|
|
its least significant word is passed via the BX register
|
|
|
|
and the most significant word is passed via the DX register
|
|
|
|
|
|
|
|
* otherwise, all parameters are passed via static locations
|
|
|
|
|
|
|
|
#### Return values:
|
|
|
|
|
|
|
|
* one-byte return values are passed via the AL register
|
|
|
|
|
|
|
|
* two-byte return values are passed via the BX register
|
|
|
|
|
|
|
|
* in case of three-byte return values,
|
|
|
|
its least significant two bytes are passed via the BX register
|
|
|
|
and the most significant byte is passed via the DL register
|
|
|
|
|
|
|
|
* in case of four-byte return values,
|
|
|
|
its least significant word is passed via the BX register
|
|
|
|
and the most significant word is passed via the DX register
|
|
|
|
|
|
|
|
* otherwise, the return value is passed via a static location
|
|
|
|
|
|
|
|
#### Register preservation:
|
|
|
|
|
|
|
|
* callee may clobber all flags
|
|
|
|
|
2019-10-22 00:01:18 +00:00
|
|
|
* callee may clobber all registers except for SP and BP
|
|
|
|
|
|
|
|
## 6809
|
|
|
|
|
|
|
|
**WARNING!** Motorola 6809 support is not yet complete.
|
|
|
|
|
|
|
|
**TODO: this convention may change**
|
|
|
|
|
|
|
|
#### Parameters:
|
|
|
|
|
|
|
|
* if the function has one parameter of size one byte, it is passed via the B register
|
|
|
|
|
|
|
|
* if the function has one parameter of size two bytes, it is passed via the D register
|
|
|
|
|
|
|
|
* otherwise, all parameters are passed via static locations
|
|
|
|
|
|
|
|
#### Return values:
|
|
|
|
|
|
|
|
* one-byte return values are passed via the B register
|
|
|
|
|
|
|
|
* two-byte return values are passed via the D register
|
|
|
|
|
|
|
|
* otherwise, the return value is passed via a static location
|
|
|
|
|
|
|
|
#### Register preservation:
|
|
|
|
|
|
|
|
* callee may clobber all flags
|
|
|
|
|
|
|
|
* callee may clobber all registers except for S and U
|