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
Which compiler are you using?
NC100 compiler with HEW IDE
You are right the original error was due to the ".c" but when I removed it the error is now: Undefined symbol exist '_pff' despite the file is clearly included in the project under C source file directory.
Is there any working example program I can look at in order to compare with mine
Thks for your help
Is this a compiler error or a linker error for the undefined symbol?
Here is the complete error message from assembly compiler phase:
C:\0DATA\32C\32C Projects\R32C_GFORCE_GRAPHIC\R32C_GFORCE_3\main.a30R32C/100 Series Assembler system V.1.02.01Copyright (C) 2006 (2007 - 2010) Renesas Electronics Corporation.and Renesas Solutions Corporation. All rights reserved.macro processing nowassembler 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) 00001TOTAL WARNING(S) 00000TOTAL LINE(S) 05415 LINESCODE 00000625(000271H) program( C:\0DATA\32C\32C Projects\R32C_GFORCE_GRAPHIC\R32C_GFORCE_3\main.a30 )
The error shown is, "Characters exist in expression" which is quite different than "Undefined symbol..."
Sorry for late reply, I was ut for a while !
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.a30R32C/100 Series Assembler system V.1.02.01Copyright (C) 2006 (2007 - 2010) Renesas Electronics Corporation.and Renesas Solutions Corporation. All rights reserved.macro processing nowassembler processing now----*----*----*----*----*----*----*----*----*----*----TOTAL ERROR(S) 00000TOTAL WARNING(S) 00000TOTAL LINE(S) 05416 LINESCODE 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
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;
There is no good way to define a c structure in asm. You can manually define offsets in asm for the variables in the c structure. But when you change the structure you need to redefine your asm offsets.
A better way to use c structures in asm is to make use of the asm function also known as inline assembly. With this you can imbed asm in a c function. A small example from the NC100 compiler manual (chapter B2):
void func(void) { short idata; short a[3]; struct TAG{ short i; short k; } s; : asm(" MOV.W R0, $$[FB]", idata); : asm(" MOV.W R0, $$[FB]", a[2]); : asm(" MOV.W R0, $$[FB]", s.i); (Remainder omitted) : asm(" MOV.W $$[FB], $$[FB]", s.i, a[2]); }
And:
short idata; short a[3]; struct TAG{ short i; short k; } s; void func(void) { : asm(" MOV.W R0, $$", idata); : asm(" MOV.W R0, $$", a[2]); : asm(" MOV.W R0, $$", s.i); (remainder omitted) : }
Thks NGE for your quick answer but my purpose is to call C from asm and not the opposite.
My main project is in assembly and I just wanted to access a driver for sd card written in C
The question is how to define an @ in RAM for the C structure not to define it in asm
I would approach this by having the C-code do all structure references using function calls from the assembly side read / write individual structure data:
struct { int Member1; int Member2; int Member3:} Struct;int Get1(void) { return Struct.Member1; }int Get2(void) { return Struct.Member2; }int Get3(void) { return Struct.Member3; }void Put1(int Arg) { Struct.Member1 = Arg: }void Put2(int Arg) { Struct.Member2 = Arg; }void Put3(int Arg) { Struct Member3 = Arg: }
I do not understand: where are the function calls from the assembly side read / write individual structure data in your example ?
From assembly when you need to access the structure from the C-code, call the "Get" for a read and "Put" for a write.