Your assembly-language procedure can return a value to a C calling program. All return values of four bytes or less are passed in registers. Far pointers to return values larger than four bytes are returned in the DX and AX registers. The DX register contains the segment address; the AX register contains the offset relative to the segment contained in DX.
Table 11.3 shows the register conventions for returning simple data types to a C program.
Table 11.3 Register Conventions for Simple Return Values
Data Type | Registers |
char | AL |
int, short, __near * | AX |
long, __far * | High-order portion (or segment address) in DX; low-order portion (or offset address) in AX |
Summary: Your procedures can return structures.
To return a structure from a procedure that uses the C calling convention, you must copy the structure to a global variable, then return a pointer to that variable in the AX register (DX:AX, if you compiled in compact, large, or huge model).
Procedures that use the FORTRAN/Pascal calling convention return structures similarly, with the following exceptions:
The calling program allocates space for the return value on the stack.
The calling program passes a pointer to the location where the return value is to be placed in a hidden parameter.
Instead of copying your structure into a global data item, you copy it into the location pointed to by the hidden parameter.
You must still return the pointer to that location in the AX register (or DX:AX for far data models).
Summary: You can return floating-point values from your procedures.
Procedures that use the C calling convention and return type float or type double must always copy their return values into the global variable __fac. To return floating-point values from procedures declared with the FORTRAN/Pascal calling convention, you must return the result on the stack, just as you would a structure.
To return a value of type long double, you must place the value on the NDP (80x87) stack using the FLD instruction. The C run-time math routines guarantee that the only value on the NDP stack is a return value; your routines must observe the same rule.