View previous topic :: View next topic |
Author |
Message |
lozzik
Joined: 03 Nov 2006 Posts: 12
|
How to add code to specific location |
Posted: Thu Jul 29, 2010 3:28 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Thu Jul 29, 2010 4:04 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
lozzik
Joined: 03 Nov 2006 Posts: 12
|
|
Posted: Thu Jul 29, 2010 4:28 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
lozzik
Joined: 03 Nov 2006 Posts: 12
|
|
Posted: Thu Jul 29, 2010 4:32 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
lozzik
Joined: 03 Nov 2006 Posts: 12
|
|
Posted: Thu Jul 29, 2010 12:20 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Thu Jul 29, 2010 2:45 pm |
|
|
Type it into an assembler, or read the manual. Both are free.... |
|
![](templates/subSilver/images/spacer.gif) |
lozzik
Joined: 03 Nov 2006 Posts: 12
|
|
Posted: Thu Jul 29, 2010 11:57 pm |
|
|
Thank you for your help (it was also free :P )
I will figure something out.
Best regards |
|
![](templates/subSilver/images/spacer.gif) |
lozzik
Joined: 03 Nov 2006 Posts: 12
|
|
Posted: Fri Jul 30, 2010 1:36 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
miketwo
Joined: 04 Aug 2010 Posts: 24
|
|
Posted: Thu Sep 16, 2010 3:26 pm |
|
|
Thank you lozzik, that was very helpful. |
|
![](templates/subSilver/images/spacer.gif) |
|