View previous topic :: View next topic |
Author |
Message |
FGazier Guest
|
Call a C function from a asm code ? |
Posted: Mon Aug 20, 2007 9:01 am |
|
|
hello,
i dont arrive to call a function from a asm code declared between the beacon #asm ... #endasm.
Code: |
#INT_GLOBAL
isr()
{
#asm
/* Rb0 : */
btfsc INTCON, INT0IE
btfss INTCON, INT0IF
bra finIntHP
/*endasm
intRb0(); /* RUN !!!*/
#asm*/
call intRb0 /* BUT NOT HERE*/
bcf INTCON, INT0IF
bra finIntHP
finIntHP:
retfie FAST
#endasm
}
void intRb0(void)
{
ledverte = !ledverte;
}
=>
*** Error 72 "D:\Projet\Projet Pic\test\ccs\18 f 258\flashLed.c" Line 233(1,7): Incorrectly constructed label
|
I dont arrive to bind C function with asm.
I have test to declare label or call _intRb0 or _intRb0_ or other but nothing run.
Thanks |
|
|
Douglas Kennedy
Joined: 07 Sep 2003 Posts: 755 Location: Florida
|
|
Posted: Mon Aug 20, 2007 10:31 am |
|
|
A function needs to be either forward referenced or actually declared before
the compiler encounters its use. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Fgazier Guest
|
Re |
Posted: Mon Aug 20, 2007 11:11 am |
|
|
Yes ,I know and I use that but this way isn't very beautiful ...
but more pesky is that, I can work with asm declaration (... EQU ...) and I dont arrive to master the whole compilation, assemblage and binding.
PS : with other compiler, for using label asm in C, we must add __ before each label. May be there is the same trick in CCS.
=> here it is the inverse. |
|
|
kevcon
Joined: 21 Feb 2007 Posts: 142 Location: Michigan, USA
|
|
Posted: Mon Aug 20, 2007 11:58 am |
|
|
Why do you need to use assembly?
Everything you posted can be handled with c statements.
Just an example
Code: |
#pragma byte INTCON = getenv( "SFR:INTCON" )
#pragma bit INT0IE = INTCON.4
#pragma bit INT0IF = INTCON.1
#pragma INT_GLOBAL
void isr( )
{
if ( !INT0IE )
return;
if ( INT0IF }
return
intRb0();
}
|
|
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9236 Location: Greensville,Ontario
|
|
Posted: Tue Aug 27, 2019 4:02 pm |
|
|
he could also just convert the line...
ledverte = !ledverte;
into asm... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Tue Aug 27, 2019 11:47 pm |
|
|
You don't say 'what PIC'?.
Important, since a lot of PIC18's have a bug with the RETFIE FAST
instruction. If your chip has this, you will need to be saving the registers
yourself... |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Mon Sep 02, 2019 4:28 pm |
|
|
Mine are the 4620 and 46k42.
The question is actually how does CCS see the C defined functions in the #asm blocks. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19535
|
|
Posted: Mon Sep 02, 2019 11:51 pm |
|
|
Basically it doesn't.
The way to call a C function, is to do it in C as is shown. The C function
is not a label that can be called, and the compiler can change it's mind
about whether a function is callable or jumpable to (or even inline).
'Called' in C, the compiler will keep track of the various forms, and
correctly handle all three methods. Trying to do it directly from assembler
is 'asking for problems'. |
|
|
|