uvision 2 v2.40, c51 v7.09, bl51 v5.03 gives: *** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS SEGMENT: ?PR?IS_OK_INC_DTARGET_SPD?SPDLIM spdlim.c has bit IS_OK_INC_DTARGET_SPD( void ) which returns a bit. (1) how do I fix this?
Forgot to mention that the a51 file that calls the C file has: EXTRN CODE ( IS_OK_INC_DTARGET_SPD ) If a C file (instead of the A51 file) calls IS_OK_INC_DTARGET_SPD(), there are no warnings or errors. If I change 'code' to 'bit', i.e., EXTRN BIT ( IS_OK_INC_DTARGET_SPD ) there is an a51 A46 CODE-ADDRESS EXPECTED error.
Have you got the naming convention correct? C51 puts various prefixes on the generated name to indicate things like return type & register usage - check the Manual Or, try writing a dummy call in 'C', and see what assembler it generates.
The lst gives: IS_OK_INC_DTARGET_SPD. PUBLIC CODE PROC 0000H ----- and the link map shows CODE 35A8H 0096H INBLOCK ?PR?IS_OK_INC_DTARGET_SPD?SPDLIM for the PRogram part and BIT 0020H.3 0000H.1 UNIT ?BI?IS_OK_INC_DTARGET_SPD?SPDLIM which, I assume, is for the return value. By the way, I read the C manual (Bit Types, p. 98 and Func. Return Values, p. 120) before my original post. I did not see any special note or warning for interfacing C to assy where the return value from a C function is BIT. Am I missing something?
Created main.c, cf.c, af.a51 for project. The following paste does not show main's call to af(). This simple example still shows the linker warning.
// cf.c bit cf( void ); bit cf( void ) { bit retval; retval = 1; return ( retval ); }
;; af.a51 CS SEGMENT CODE RSEG CS extrn code ( cf ) public af af: call cf ret END
(In my opinion) The ONLY way to make assembler functions that can be seamlessly called from C is to make a skeleton function in C and use the generated assembler as a template. Make sure all variables are used in the skeleton. Erik
IMHO, the problem is calling a C function from assembly, not calling assembly from C.
IMHO, the problem is calling a C function from assembly, not calling assembly from C. To which the same strategy applies: do it (correctly, i.e. with a prototype declaration of the called function in scope) in a C program, and have C51 make you A51 soruce code demonstrates what exactly has to be done. That's the single most important rule about mixed assembly + C programming: the compiler knows how to do it, so don't ever hesitate to ask it.