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

Can I reallocate which area of RAM is used by the compiler

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



Joined: 17 Nov 2005
Posts: 30
Location: Chester UK

View user's profile Send private message

Can I reallocate which area of RAM is used by the compiler
PostPosted: Thu Apr 20, 2006 3:30 am     Reply with quote

Is it possible to force the compiler to use different areas of RAM if for it's internal affairs? For example supposing I wanted to use the first 32 bytes from 0x00 to 0x1F for my own use and let the compiler use the remaining ramspace?

The following program doesn't do anything special but is useful for illustrating my qeury.
Code:
#device PIC18F4331
#define VARIABLE_ADDR   0x002
#reserve VARIABLE_ADDR, VARIABLE_ADDR
int   variable;
#locate variable=VARIABLE_ADDR
#org   0x0200,0x02FF
void main(void)
{
   while(1) variable++;
}

As it stands this compiles OK, however if I change VARIABLE_ADDR to 0x001 or 0x000 I get the following compilation error:
    Error 103 : Constant out of the valid range 001 is reserved by the compiler

I appreciate that the compiler may need to use additional RAM at some point, however when I examine the dissasembly file I cannot see anywhere where RAM locations 0x000 or 0x001 are being used?

Code:
1:                 #device PIC18F4331
  0000    EF00     GOTO 0x200
2:                 #define VARIABLE_ADDR   0x002
3:                 #reserve VARIABLE_ADDR, VARIABLE_ADDR
4:                 int   variable;
5:                 #locate variable=VARIABLE_ADDR
6:                 #org   0x0200,0x02FF
7:                 void main(void)
8:                 {
  0200    6AF8     CLRF 0xff8, ACCESS       // Clear TBLPTRU
  0202    9ED0     BCF 0xfd0, 0x7, ACCESS   // Disable interrupt priority
  0204    6AEA     CLRF 0xfea, ACCESS       // Clear FSR0H
  0206    6AE9     CLRF 0xfe9, ACCESS       // Clear FSR0L
  0208    90B9     BCF 0xfb9, 0, ACCESS     // Clear bit 0 of ANSEL1,
  020A    9CC1     BCF 0xfc1, 0x6, ACCESS   // Clear bit 6 of ADCON1,
  020C    9EC1     BCF 0xfc1, 0x7, ACCESS   // Clear bit 7 of ADCON1,
  020E    0E00     MOVLW 0                  // Write literal of 0 into W
  0210    6EB8     MOVWF 0xfb8, ACCESS      // Copy W into ANSEL0
9:                    while(1) variable++;
  0212    2A02     INCF 0x2, F, ACCESS      // Increment RAM at 0x02
  0214    D7FE     BRA 0x212                // Loop back one
  0216    0003     SLEEP


Thanks,
Ben
Ttelmah
Guest







PostPosted: Thu Apr 20, 2006 7:07 am     Reply with quote

Use somewhere else!...
Three comments. 'Reserve', is designed to _stop_ the compiler using the area, then you tell it to put a variable into this area. If you want other code to use an area, reserve it. If you want to force a variable to a particular location, locate it. Don't do both to the same area.
Second comment, the syntax for reserve, is start address:end address.
Third comment. The reason for the problem, is that the first area of memory, is the 'access bank', useable in all pages of memory. The compiler doesn't make much use of this ability, but uses the first four bytes, for it's scratch area....

Best Wishes
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