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 place assembly code BEFORE main()

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



Joined: 20 Sep 2004
Posts: 14
Location: Sacramento, CA

View user's profile Send private message

How to place assembly code BEFORE main()
PostPosted: Tue Dec 28, 2004 4:06 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Dec 28, 2004 4:15 pm     Reply with quote

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.
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