Calling C function from asm prog

Hi there,

I am still struggling to call a C function from an assembler program

Here is the command used:

jsr $pff.c   I tried also jsr _pff.c

The result is always the same:

Error (asp100): Characters exist in expression

Any clue ?

Thks in advance for your help

Jean-Pierre

Parents Reply
  • Here is the complete error message from assembly compiler phase:

    C:\0DATA\32C\32C Projects\R32C_GFORCE_GRAPHIC\R32C_GFORCE_3\main.a30
    R32C/100 Series Assembler system V.1.02.01
    Copyright (C) 2006 (2007 - 2010) Renesas Electronics Corporation.
    and Renesas Solutions Corporation. All rights reserved.
    macro processing now
    assembler processing now
    ----*----*----*----*----*----*----*----*----*----*-
    C:\0DATA\32C\32C Projects\R32C_GFORCE_GRAPHIC\R32C_GFORCE_3\main.a30(461) : Error (asp100): Characters exist in expression
    ---
    TOTAL ERROR(S) 00001
    TOTAL WARNING(S) 00000
    TOTAL LINE(S) 05415 LINES
    CODE 00000625(000271H) program
    ( C:\0DATA\32C\32C Projects\R32C_GFORCE_GRAPHIC\R32C_GFORCE_3\main.a30 )

Children
  • The error shown is, "Characters exist in expression" which is quite different than "Undefined symbol..."

  • Sorry for late reply, I was out for a while ! 

    When the command is: jsr $pff.c

    the error is: Error (asp100): Characters exist in expression

    When the command is: jsr $pff

    the error is: Error (asp100): Undefined symbol exist '$pff'

    Errors are the same if I used '_' instead of '$'

    Here is the list of C files included in the project

    That would be great if I could find a sample program calling a C function from an assembly program !

  • Can you generate the assembly code for the "pff.c" (or the assembler listing)?

  • This is an assembler error because you have an undefined name. I have used the NC30 compiler a lot for R8C devices. And there you also needed to define the c function name. Assuming your c function is pff() then you need todo the following:

    .glb    _pff
    
    jsr     _pff

    The assembler will then recognise the name. And the linker should than link it to the c file.

  • That makes sense - some assemblers require symbol references, some don't, and some have options to ignore undefined symbols.  One could also potentially get the C-compiler to generate such a reference by doing something like this:

    extern int pff; int GetPFF(void) { return pff; }

  • Thanks NGE, you were right !

    I did have a '.glb' declaration but I forgot the underscore character (shame on me...)

    Now the compilation process is completed without any error (see below)

    assembler processing now

    C:\0DATA\32C\32C Projects\R32C_GFORCE_GRAPHIC\R32C_GFORCE_3\main.a30
    R32C/100 Series Assembler system V.1.02.01
    Copyright (C) 2006 (2007 - 2010) Renesas Electronics Corporation.
    and Renesas Solutions Corporation. All rights reserved.
    macro processing now
    assembler processing now
    ----*----*----*----*----*----*----*----*----*----*----
    TOTAL ERROR(S) 00000
    TOTAL WARNING(S) 00000
    TOTAL LINE(S) 05416 LINES
    CODE 00000629(000275H) program
    ( C:\0DATA\32C\32C Projects\R32C_GFORCE_GRAPHIC\R32C_GFORCE_3\main.a30 )
    ----*----*--
    Phase R32C/100 Assembler finished

    But now linkage pass 2 is faulty, see result below:

    Phase R32C/100 Linker starting

    Linkage Editor (ln100) for R32C/100 Series V.1.02.00.001

    Copyright (C) 2006 (2007 - 2010) Renesas Electronics Corporation.

    and Renesas Solutions Corporation. All rights reserved.

    SentinelRMS (C) 1989-2006 SafeNet, Inc. All rights reserved.

    now processing pass 2

    Projects\R32C_GFORCE_GRAPHIC\R32C_GFORCE_3\Debug\main.r30"

    C:\0DATA\32C\32C Projects\R32C_GFORCE_GRAPHIC\R32C_GFORCE_3\main.a30(461) : '_pff' value is undefined

    Any clue ?

  • I dived in an old project with a R32C/111 where in the C file I have the following:

    void initSystem(void);
    
    void initSystem(void){
    
    }

    The declaration of the function can also done in an include. Maybe this declaration is needed for the linker.

    And in the assembly:

    .glb		_initSystem
    jsr.a		_initSystem

  • It's now working fine !

    I used the following:

    jsr _pff to call a simple C function and

    jsr $open when parameters have to be transmitted

    Many thanks NGE for your kind help !!

  • Following successfully calling C functions from asm, I am now facing a new issue:

    My data are defined as follows in asm project

    ;********************************************************
    ; RAM area allocation
    ;********************************************************

    .section data_SB8, data

    record_size: .blkl 1

    but I don't know how to include variable and structure defined in C language functions to my data section

    defined in asm

    Here is an example of a structure defined in H file

    /* Directory object structure */

    typedef struct {
    WORD index; /* Current read/write index number */
    BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
    CLUST sclust; /* Table start cluster (0:Static table) */
    CLUST clust; /* Current cluster */
    DWORD sect; /* Current sector */
    } DIR;

    and variable defined in C file like:

    BYTE i, c;

    Thks for your help