hello at all,
i need to modify an old program write in asm, I'm able to call a C-function from the ASM main program, with the following declaration:
.glb
_ExampleCsubroutine
and in c source I declare for example:
void ExampleCsubroutine(void);
...within this all it'ok but, if, in a C subroutin, I want work on a variable declared in asm (.inc file) how I can do ??
I have try to find this in information in other post without result..
in advance many thanks
For which processor? Using which compiler?
the processor family:
M16C/62P (M30624FGP)
the compiler is HPEW v4.05.01.001
and the emulator is E8.
Regardless of which assembler and compiler you use, the general idea is like this:
In the asm file, declare the variable of the appropriate size using a name that has an underscore before it (e.g. _foo).
You must also declare it to be globally visible, like this:
.glb _foo
In the C compilation unit (perhaps in a header file), you have to declare a variable (with the "extern" qualifier) of the type you are accessing, then reference it in your code. In both cases you do not use the underscore.
extern unsigned in foo;
...
a = foo * 2;
...
That should do it.
I have try the following code:
(file zzvar.inc)
.section variabili,DATA
.org 01800h
.glb _VoltLavoro
VoltLavoro: .blkw 1
-----------------------------------------------------------------------------------------------
(file ncrt0.a30 where is the uP initialization and the main code )
;include file
.list OFF
.include zzvar.inc
.....
.list ON
.....
....
loop:
.glb _main ; main C subroutine declared in csource.c
jsr.a _main
-----------------------------------------------------------------------------------------------
(file csource.c)
#include "csource.h "
void main(void)
{
..........
VoltLavoro++;
..........
}
-----------------------------------------------------------------------------------------------
(file csource.h)
extern unsigned int VoltLavoro;
-----------------------------------------------------------------------------------------------
compiling this code the HPEW return the following error during 'MC16C C Compiler Starting' :
Error (ccom) unknow variable VoltLavoro
if I use
extern unsigned int VoltLavoro;
in csource.c file and comment the same declaration in csource.h file I have an error in the linker (Phase M16C linker starting) :
error (ln30) '_VoltLavoro' value is undefined
Sorry, but why don't you define the variable in C and reference it from your assembler file?
This is easier, and it is much better for debugging.
If you define a variable in assembler you cannot see it in the debugger. Strictly speaking, in assembler you do not define a variable but you define an assembler symbol and reserve some memory space for at the address of this symbol.
For example, you will not be able to see this variable in the variable watch window in the debugger. The debugger does not know anything about the variable type.
The linker error may come because you do not have the underscore at the beginning of the assembler symbol. In the assembler file you have the underscore in the .glb instruction, but not in the next line.
And a small question, why write assembler from scratch anyway? I would prefer to write a routine in C, tell the compiler to produce an assembler source file, and then if I think it is worth the time modify the compiler generated assembler source. Then you can see how the compiler defines a variable (it adds several additional instructions as debug information).
To mbarkley: It is important which compiler is used as IAR compiler don't add a leading underscore to the variable name.
..I have an old program write in asm where the variable is used and in some asm function the variable access is done by pointer...
my idea was reference this variable in C and use it in a C function in order to insert in the asm code only the calling of C function
you write
- Sorry, but why don't you define the variable in C and reference it from your assembler file?
but if is important the memory address of this variable (because in asm code the variable access is done by pointer), how I can do it?
you write
-And a small question, why write assembler from scratch anyway?
The most important part of code of this project is already written in assembler,(that i don't like) i need only insert in this code some modify written in C ...but I need do some operation on variable used also in asm code
You can assign an address to a C variable using #pragma ADDRESS, but this will not help. A variable with an associated #pragma ADDRESS is not treated as variable regarding the debug information, so you cannot see it in the debugger. And a variable defined with #pragma ADDRESS doies not reserve memory. It is simply a reference to a variable.
Some more thoughts about your software:
- You cannot get access to your assembler symbol from C because it most probably has no leading '_'. Variable names in C have on assembler level always a leading '_'.
- You have to modify your assembler code anyway as you have to add the '_' to your assembler symbol. So you can also use a variable name defined by a C variable.
- I hope the code initialising the assembler pointer also uses the assembler symbol name. Then the replacement is no problem.
- If the assembler symbol has been defined with .blkb it most probably does not have a fixed address, but is also relocate in a section defined with .SECTION command.
ok !! thanks for your help I have declare in .inc file
.glb _pippo
_pippo: blkw 1
and replace in .a30 file pippo with _pippo
then in .c file declare
extern unsigned int pippo
and all it's ok.
for debugg pippo I can use
unsigned int test;
test = pippo ;
and put in watch windows test or otherway check the value of memory address of pippo in memory window .
©2003–2009 Renesas Technology Corp. All rights reserved. Using Our Website | Privacy
Contact us