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 support@ccsinfo.com

How to add code to specific location

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



Joined: 03 Nov 2006
Posts: 12

View user's profile Send private message

How to add code to specific location
PostPosted: Thu Jul 29, 2010 3:28 am     Reply with quote

Hi All,

CCS generates lots of code before first line in main function.

How can I add code before all those initializing codes.

It is not too much code that I want to add, just a few asm codes.

(The code I will add has to be executed before anything else).

Thanks in advance.
Ttelmah



Joined: 11 Mar 2010
Posts: 19337

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 4:04 am     Reply with quote

The answer depends a bit on whether you are using interrupts?.

If not, then simply use #build, to put the 'reset' location at (say) 0x20. Then have a #ROM statement, containing the byto sequence you want before this point.

If you are, then compile the code once, to find out how large all the interrupt handlers are. Say they are 0xf8 bytes till the last instruction. You can then use #build with the interrupt vector left at the standard address, and the reset vector put enough bytes above the last interrupt instruction, for the code you want.
Then two #ROM statements. The first at address 0, just being a jump to the instruction after the interrupt code. The second placed at this location, containing your extra code, and ending at the required location (or ending earlier, with a jump to the specified 'reset' location.

Best Wishes
lozzik



Joined: 03 Nov 2006
Posts: 12

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 4:28 am     Reply with quote

Thank you for your quick answer.

I am using interrupts in my program.

Actually I have a custom bootloader.

I have the main at 0x400 ( #build(reset = 0x0400) ).

Bootloader code starts at 0x7C00 (at the bottom of memory).

I want jump to 0x7C00 at startup.
If there is no need to bootload, it will jump back to 0x400 which is main function.

I am using pic18f4550 and compiler is "4.093".

Best regards
lozzik



Joined: 03 Nov 2006
Posts: 12

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 4:32 am     Reply with quote

And by the way,

0x400 is enough for my interupt code and its at (0x0142).

How am I going to use the #rom for adding code to address 0 ?

I want "goto 0x7C00" at address 0.
lozzik



Joined: 03 Nov 2006
Posts: 12

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 12:20 pm     Reply with quote

Ttelmah wrote:
The answer depends a bit on whether you are using interrupts?.

If not, then simply use #build, to put the 'reset' location at (say) 0x20. Then have a #ROM statement, containing the byto sequence you want before this point.

If you are, then compile the code once, to find out how large all the interrupt handlers are. Say they are 0xf8 bytes till the last instruction. You can then use #build with the interrupt vector left at the standard address, and the reset vector put enough bytes above the last interrupt instruction, for the code you want.
Then two #ROM statements. The first at address 0, just being a jump to the instruction after the interrupt code. The second placed at this location, containing your extra code, and ending at the required location (or ending earlier, with a jump to the specified 'reset' location.

Best Wishes

Hi Ttelmah

Do you know what the data should be,

I tried #rom 0 = {????}
It is generating the code but what is the data for
GOTO 0X7C00

Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19337

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 2:45 pm     Reply with quote

Type it into an assembler, or read the manual. Both are free....
lozzik



Joined: 03 Nov 2006
Posts: 12

View user's profile Send private message

PostPosted: Thu Jul 29, 2010 11:57 pm     Reply with quote

Thank you for your help (it was also free :P )

I will figure something out.

Best regards
lozzik



Joined: 03 Nov 2006
Posts: 12

View user's profile Send private message

PostPosted: Fri Jul 30, 2010 1:36 am     Reply with quote

Hi

I solved my problem,

in case of anybody else needs something like that
Code:

#build(reset = 0x0400)

#ORG 0x0000,0x0006
void jump_to_boot_control()   
{
   #asm GOTO 0x7D00 #endasm
}

#ORG 0x7D00,0x7FFF   
void BootLoad()
{
//look for bootload
//if not goto 0x400 which is main
}


Best wishes
miketwo



Joined: 04 Aug 2010
Posts: 24

View user's profile Send private message

PostPosted: Thu Sep 16, 2010 3:26 pm     Reply with quote

Thank you lozzik, that was very helpful.
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