This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

EXTRN CODE ( FUNCTION ) gives L16 if FUNCTION is BIT

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
    

    I edited the map for space and pasted it below:

    BL51 BANKED LINKER/LOCATER V5.03 04/08/2004 14:01:08 PAGE 1

    BL51 BANKED LINKER/LOCATER V5.03, INVOKED BY:
    C:\KEILC51\C51\BIN\BL51.EXE STARTUP.obj,
    bitmain.obj,
    af.obj,
    cf.obj
    TO bitbug IXREF RAMSIZE (256)

    MEMORY MODEL: SMALL

    INPUT MODULES INCLUDED:
    STARTUP.obj (?C_STARTUP)
    bitmain.obj (BITMAIN)
    af.obj (AF)
    cf.obj (CF)

    LINK MAP OF MODULE: bitbug (?C_STARTUP)

    TYPE BASE LENGTH RELOCATION SEGMENT NAME
    -----------------------------------------------------

    * * * * * * * D A T A M E M O R Y * * * * * * *
    REG 0000H 0008H ABSOLUTE "REG BANK 0"
    0008H 0018H *** GAP ***
    BIT 0020H.0 0000H.1 UNIT ?BI?CF?CF
    0020H.1 0000H.7 *** GAP ***
    IDATA 0021H 0001H UNIT ?STACK

    * * * * * * * C O D E M E M O R Y * * * * * * *
    CODE 0000H 0003H ABSOLUTE
    CODE 0003H 000CH UNIT ?C_C51STARTUP
    CODE 000FH 0005H UNIT ?PR?CF?CF
    CODE 0014H 0004H UNIT CS
    CODE 0018H 0003H UNIT ?PR?MAIN?BITMAIN

    NAME . . . . USAGE MODULE NAMES
    ----------------------------------

    ?C_START . . CODE; ** L51 GENERATED ** ?C_STARTUP
    ?C_STARTUP . CODE; ?C_STARTUP BITMAIN
    AF . . . . . CODE; AF BITMAIN
    CF . . . . . CODE; CF AF
    MAIN . . . . CODE; BITMAIN

    *** WARNING L16: UNCALLED SEGMENT, IGNORED FOR OVERLAY PROCESS
    SEGMENT: ?PR?CF?CF

    Program Size: data=9.1 xdata=0 code=27
    LINK/LOCATE RUN COMPLETE. 1 WARNING(S), 0 ERROR(S)

  • (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.