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

questions for those who have experience with #org

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



Joined: 03 Feb 2004
Posts: 5

View user's profile Send private message

questions for those who have experience with #org
PostPosted: Fri Apr 09, 2004 10:25 am     Reply with quote

Hi. I'm using PCM v3.163 and PIC16F877. I need to reduce code size and I've noticed that about 1/10 of the assembly code deals with the A.3 and A.4 bits. I haven't yet looked at how good the compiler is at distributing functions among ROM pages, but I'm guessing I can make some improvements. So I want to start manually mapping functions to ROM pages using #org.

1)are there any known compiler bugs associated with #org?

2)how do I avoid interfering with things like the interrupt handler and all that other code the compiler places in page0?

3)I don't know of an easy way to get the size of my functions, so I don't want to explicitly locate functions - I just want to specify which page they should be in. If I understood the manual correctly, I do this using
#org 0x00, 0x800
function1_in_page0() {}
#org 0x00
function2_in_page0()
will this work?

4)when is it better to use
#org start,end DEFAULT
#org DEFAULT

5)will the compiler put out an error message if I put too many functions in a segment?

6)using #org as above doesn't change the way the compiler alocates RAM variables right?


Thanks for any help
-Ben
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Apr 09, 2004 12:22 pm     Reply with quote

1)are there any known compiler bugs associated with #org?
I don't think so.

2)how do I avoid interfering with things like the interrupt handler
and all that other code the compiler places in page0?
The compiler won't let you do it. You'll get an "invalid ORG range" error.

3)I don't know of an easy way to get the size of my functions, so I don't
want to explicitly locate functions - I just want to specify which page they
should be in. If I understood the manual correctly, I do this using
#org 0x00, 0x800
function1_in_page0() {}
#org 0x00
function2_in_page0()
will this work?

It won't work because the reset and interrupt code goes at locations 0
and 4, respectively, for the 16F877. The interrupt dispatcher could be
100 ROM words long, depending on how many interrupt service routines
you have. So you'll have to set the starting address of the first
segment to a number greater than 0. Use 0x100 to be perfectly sure
it will compile. Or, try smaller values until it compiles without error.

Also, your proposed segment end address of 0x800 is not corrrect.
The end address of the 1st ROM page is 0x7FF.


4)when is it better to use
#org start,end DEFAULT
#org DEFAULT
The default statement will move the internal routines, such as "DIV8"
into the segment specified with the Default keyword. But that's only
done if the code that invokes the internal library routines occurs AFTER
the initial Default statement.


5)will the compiler put out an error message if I put too many functions in a segment?
Definitely.

6)using #org as above doesn't change the way the compiler allocates RAM variables right?
I don't know.


Here is a sample program. I suggest you experiment with it,
and look at the .LST file and the Program Memory window in
MPLAB, to see where the compiler is putting the code.

Code:
#include <16F877.h>
#device *=16
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
//#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

#define ROM_SEGMENT_0_START  0x0100   // Allow space for reset and interrupt code
#define ROM_SEGMENT_0_END    0x07FF

#define ROM_SEGMENT_1_START  0x0800   
#define ROM_SEGMENT_1_END    0x0FFF

#define ROM_SEGMENT_2_START  0x1000   
#define ROM_SEGMENT_2_END    0x17FF

#define ROM_SEGMENT_3_START  0x1800   
#define ROM_SEGMENT_3_END    0x1FFF

#separate
char my_func(char x, char y);

//=======================================

#org ROM_SEGMENT_0_START, ROM_SEGMENT_0_END
main()
{
char a, b, c;


//a = b / c;
a = my_func(b, c);


while(1);

}
//=========================================

#org ROM_SEGMENT_1_START, ROM_SEGMENT_1_END DEFAULT

char my_func(char x, char y)
{
char retval;

retval = x / y;

return(retval);

}

#org DEFAULT


Notice that I had to use #separate, in order to use a function prototype.
Doing so will cause the compiler to not give any error message if
you use too many stack levels. So you have to watch it manually,
by checking the .LST file. This could be prevented by putting main()
at the bottom of the file. Maybe there's some other method ?
I don't have time to investigate this further.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Fri Apr 09, 2004 4:58 pm     Reply with quote

Just a quick note; it seems there were a few issues associated with #org and they have been fixed in version 3.189 (released today), as per CCS' changelog.
truevenik



Joined: 03 Feb 2004
Posts: 5

View user's profile Send private message

copies of a fucntion
PostPosted: Fri Apr 09, 2004 5:12 pm     Reply with quote

Hi, lets say I have a function g(int x). Is there a way to make two copies of it and put one in ROM page1, and another in page2 ?
Also, does anyone know of a way to use #org on a function, keep the function's prototype (so that functions can be arranged in any order in a source file), and not have to make the function #seperate (so that stack depth is still checked by the compiler) ?

thanks
-Ben
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