View previous topic :: View next topic |
Author |
Message |
Beppe
Joined: 02 Mar 2004 Posts: 1
|
Pointer to function using #ASM |
Posted: Tue Mar 02, 2004 5:42 am |
|
|
I read is not possible in CCS to obtain a pointer to a function.
So I thought I could obtain it by an assembly sobroutine and using the symbol table... i.e.:
void
my_function(){
}
main() {
....
#ASM
MOVFF my_function, FSR0L
//or something similar
#ASM
...
}
I tried this but compiler reports the following error: "Expression must evaluate to a constant"... I can't understand why! I looked at the symbol table and to the symbol my_function is rightly assigned the program memory address of th function!
Could anyone help me, please?
Thanks!! |
|
|
mpfj
Joined: 09 Sep 2003 Posts: 95 Location: UK
|
|
Posted: Tue Mar 02, 2004 6:03 am |
|
|
You're almost there ... !!
What you can do is use the #org directive to force the function to a known location .. e.g.
Code: | #org 0x8000, 0x81ff
void function(void) {
}
|
You can then use the following to call the function ...
Code: | #asm
call 0x8000
#endasm
|
The downside is that you can't pass parameters, although you can just make them globals and the you're away !! |
|
|
Ttelmah Guest
|
Re: Pointer to function using #ASM |
Posted: Tue Mar 02, 2004 11:08 am |
|
|
Beppe wrote: | I read is not possible in CCS to obtain a pointer to a function.
So I thought I could obtain it by an assembly sobroutine and using the symbol table... i.e.:
void
my_function(){
}
main() {
....
#ASM
MOVFF my_function, FSR0L
//or something similar
#ASM
...
}
I tried this but compiler reports the following error: "Expression must evaluate to a constant"... I can't understand why! I looked at the symbol table and to the symbol my_function is rightly assigned the program memory address of th function!
Could anyone help me, please?
Thanks!! |
Actually pointers to functions, _are_ now supported (though with significant 'caveats').
Best Wishes |
|
|
|