Joined: 20 Sep 2004 Posts: 14 Location: Sacramento, CA
How to place assembly code BEFORE main()
Posted: Tue Dec 28, 2004 4:06 pm
Is there any way to get the compiler to allow you to place some ASM code BEFORE main() (and before the compiler generated initialization code that appears at the beginning of main())?
I have considered (but have not yet tried) "taking over" the startup vector with #org 0, placing my own initialization code near the end of a segment and then calling (GOTO) main() at the end of my initialization code. In my current application I need to have the first couple of instructions executed setup several of the the pins in specific states AS SOON AS power is applied (PIC16LF819 processor).
There isn't any mention of this (or something like __main(), the usual method with other compilers) in the CCS manual and rather than spend time randomly experimenting I thought just asking would be more efficient! Thanks for any input you might have.
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
Posted: Tue Dec 28, 2004 4:15 pm
Many of the bootloaders use similar tricks.
From the readme.txt from v3.212
Quote:
The reset and interrupt vectors can be moved from the normal location
using #build like this:
#build(reset=0x200, interrupt=0x208)
A larger than normal area may be reserved like this:
#build(reset=0x200:0x207, interrupt=0x208:0x2ff)
Using the #org instruction you can put your code at address 0x0000 so this is called at startup. Then when your code is finished you jump to address 0x200 (or whatever address you choose) where the reset vector is relocated.
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