View previous topic :: View next topic |
Author |
Message |
Matro Guest
|
Call a part of the code by "goto" and not "ca |
Posted: Thu Mar 06, 2008 9:40 am |
|
|
Hi everybody,
I'm programming a bootloader and I'm in trouble with the memory organization and the way CCS access a function. For better understanding, let's see the following code example :
Code: |
#INLINE
void Bootloader (void)
{}
void Application (void)
{}
#ORG 0x0E00,0xFFF
void main (void)
{
//Correct Init
if(condition)
Bootloader();
else
Application();
}
|
For some reasons I'd like the "Application()" call of the "main" function to be done in the generated assembly by a "GOTO xxx" and not by a "CALL xxx".
My CCS compiler randomly generates the code with both of this 2 ways and I can't understand why (but I don't really care).
Is there a way to be sure that the compiler will build with the "GOTO" and not with the "CALL".
PIC model : 16F88
CCS version : 4.057
Thanks in advance for all your helpful answers. |
|
|
Matro Guest
|
More info |
Posted: Thu Mar 06, 2008 10:19 am |
|
|
I realized that my question wasn't totally clear because I didn't explain that the "Application()" function has to be always at the same memory address.
So the code example is better like that:
Code: |
#INLINE
void Bootloader (void)
{}
#ORG 0x0100,0x0300
void Application (void)
{}
#ORG 0x0E00,0xFFF
void main (void)
{
//Correct Init
if(condition)
Bootloader();
else
Application();
}
|
With deeper investigation, the way the function is called isn't randomly generated.
If the "#ORG" line is present just before the "Application()" function it is called with a "CALL" in the generated ASM and if it isn't present the function is called with a "GOTO".
It doesn't solve my problem but could maybe help you to find a solution. |
|
|
gribas
Joined: 21 Feb 2008 Posts: 21
|
|
Posted: Thu Mar 06, 2008 11:35 am |
|
|
Code: |
#define APP_ST_ADDRESS 0x0100
#INLINE
void Bootloader (void) {}
#ORG APP_ST_ADDRESS,0x0300
void Application (void) {}
#ORG 0x0E00,0xFFF
void main (void) {
//Correct Init
if(condition)
Bootloader();
else {
//Application
#asm
goto APP_ST_ADDRESS
#endasm
}
}
|
|
|
|
Matro Guest
|
|
Posted: Fri Mar 07, 2008 2:31 am |
|
|
Indeed, it should work. I will try it.
The problem with this method is that I have to carefully foresee the possible "return" from the "Application()" to the "main()" that shall be a "goto" too.
But it should be OK.
If somebody of the CCS team reads that thread it should be a good thing that the jump to a function called only once in the code and that is not "#INLINE" be compiled with ASM "GOTO" and not "CALL". Or maybe it should be a preprocessor option. It will save 1 stack level.
Thanks for this very helpful answer.
If somebody has another proposal feel free to append. I will read it. ;-)
Bye. |
|
|
|