View previous topic :: View next topic |
Author |
Message |
heath.g
Joined: 20 Jun 2006 Posts: 6
|
Optimization of constant pointers |
Posted: Tue Jun 20, 2006 1:15 am |
|
|
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
|
|
Posted: Tue Jun 20, 2006 3:25 am |
|
|
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
|
|
Posted: Wed Jun 21, 2006 12:52 am |
|
|
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. |
|
 |
|