CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Call a part of the code by "goto" and not "ca

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Matro
Guest







Call a part of the code by "goto" and not "ca
PostPosted: Thu Mar 06, 2008 9:40 am     Reply with quote

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
PostPosted: Thu Mar 06, 2008 10:19 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Mar 06, 2008 11:35 am     Reply with quote

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







PostPosted: Fri Mar 07, 2008 2:31 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group