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

Optimization of constant pointers

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



Joined: 20 Jun 2006
Posts: 6

View user's profile Send private message

Optimization of constant pointers
PostPosted: Tue Jun 20, 2006 1:15 am     Reply with quote

I just need some clarification on the following.

For the following code why does the compiler use the FSR to get access to the MP3A_StartAddress variable. Other compliers would evaluate this to one MOVFF instruction (PIC18), but it doesnt and it uses the FSR which requires 5 instrcutions to perform. All the variables here are constants and dont need to be calculated at runtime.

INT Buffer[4];
INT32 MP3A_StartAddress;
*(((char*)&MP3A_StartAddress) + 2) = Buffer[0];

Is there another way to optimize this or is inline assembler the only way.

Any help would be great. Thanks.
Ttelmah
Guest







PostPosted: Tue Jun 20, 2006 3:25 am     Reply with quote

It does not use the FSR to "get access to the MP3A_StartAddress variable". It uses the FSR to get access to the location _addressed_ by this variable. The problem is that CCS, assumes that variables are not necessarily static in location.
The best way to code this (since it is portable, and explicit in what is being done), is:
[code]
int8 Buffer[4];
union {
int32 MP3A_STARTAddress;
int8 b[4]
} MPB;

//Then transfer the byte with:
MPB.b[2] = Buffer[0];

//The 'word' is then accessible with:

MPB.MP3AStartAddress
[code]

Best Wishes
heath.g



Joined: 20 Jun 2006
Posts: 6

View user's profile Send private message

PostPosted: Wed Jun 21, 2006 12:52 am     Reply with quote

Thanks for the reply.

What you have written was what I was looking at doing which tells me I was going down the right path.

Its a pitty that CCS doesn't assume variables are static in which they are like other C compilers.

Anyway thems are the breaks and I will live with it.

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