Calling C from assembly

Each C function is exposed as a label in assembly. To call a C function that has no parameters or return value, simply CALL the function by name.

To pass parameters to a C function, determine the number and type of parameters. If the function requires one or two 8 bit parameters, or one 16-bit parameter, you can use the A and X registers to pass the values. Load the A register with the lowest byte of a 16-bit parameter, or the first 8-bit parameter. Load the X register with the upper byte of a 16-bit parameter, or the second 8-bit parameter. Finally, issue a call instruction using the function name as a label.

If the function requires more than 16 bits of parameters, you are responsible for setting up the parameter values in LOCAL RAM. See the listing file disassembly of the C function to determine what values to provide.

If the function returns an 8-bit value, it resides in the A register. If it returns a 16-bit value, it resides in A:X.