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

address of CONST data

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



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

address of CONST data
PostPosted: Mon May 24, 2004 9:28 am     Reply with quote

Do I undersatnd this correctly, or it there a bug ?

As of Version:
3.183 The LABEL_ADDRESS function now may be used to obtain the address of CONST data.

This code compiles OK, why does this fail at runtime ?

const char abc[]={"ABC"};

char* pChar;

pChar = (char*) Label_Address(abc);

putchar ( pChar[1] ); // runtime failure

The help files says pointers to constants are not allowed.

Label_Address() can now return the address of const data, which implies pointers to constants are allowed !.

So why does using pChar[1] fail. !
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: address of CONST data
PostPosted: Mon May 24, 2004 9:48 am     Reply with quote

Hans Wedemeyer wrote:
Do I undersatnd this correctly, or it there a bug ?

As of Version:
3.183 The LABEL_ADDRESS function now may be used to obtain the address of CONST data.

This code compiles OK, why does this fail at runtime ?

const char abc[]={"ABC"};

char* pChar;

pChar = (char*) Label_Address(abc);

putchar ( pChar[1] ); // runtime failure

The help files says pointers to constants are not allowed.

Label_Address() can now return the address of const data, which implies pointers to constants are allowed !.

So why does using pChar[1] fail. !


To me it implies that I can load a constant lookup in program memory at runtime.
Ttelmah
Guest







Re: address of CONST data
PostPosted: Mon May 24, 2004 10:13 am     Reply with quote

Hans Wedemeyer wrote:
Do I undersatnd this correctly, or it there a bug ?

As of Version:
3.183 The LABEL_ADDRESS function now may be used to obtain the address of CONST data.

This code compiles OK, why does this fail at runtime ?

const char abc[]={"ABC"};

char* pChar;

pChar = (char*) Label_Address(abc);

putchar ( pChar[1] ); // runtime failure

The help files says pointers to constants are not allowed.

Label_Address() can now return the address of const data, which implies pointers to constants are allowed !.

So why does using pChar[1] fail. !

Not quite.
Pointers to constants are not allowed, but you can use the 'Label_address' function to find where in ROM, the table is stored. This could be useful if you wanted to access the table yourself using machine code (for instance).
It is important to understand that the memory area being addressed is distinct between ROM/RAM, so using the number returned as an address, and then trying to access this as if it was a pointer will give silly values. You _may_ be able to use the value with the read_program_eeprom function (this depends on the chip being used, since on the 16F family, the actual numbers stored are 'RETLW' instructions, but on the 18F family, are just numeric values).

Best Wishes
Hans Wedemeyer



Joined: 15 Sep 2003
Posts: 226

View user's profile Send private message

Thanks... but
PostPosted: Mon May 24, 2004 10:22 am     Reply with quote

I'm using PIC186621

It sure would slim down code is I could access CONST strings by pointer, and pass pointers to CONST data...

If puts() can access a constant data, then CCS should make pointers to constants available for PIC18 part at least....

Back to jump through hoops code !
Ttelmah
Guest







Re: Thanks... but
PostPosted: Mon May 24, 2004 2:35 pm     Reply with quote

Hans Wedemeyer wrote:
I'm using PIC186621

It sure would slim down code is I could access CONST strings by pointer, and pass pointers to CONST data...

If puts() can access a constant data, then CCS should make pointers to constants available for PIC18 part at least....

Back to jump through hoops code !

You can already largely do this, using the read_program_eeprom function. If you store a table with the #ROM directive, rather than const, it avoids the compiler adding the table read 'header' for the data concerned. You can then use a numeric address in the ROM area allmost as if you were dealing with a pointer.
It is hard to implement pointers to constants in ROM. When you insert a constant string into (say) putc, as:
putc("A constant string");
Both the string, and the read header are inserted into the code, and putc is called multiple times.

Best Wishes
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Wed May 26, 2004 5:51 pm     Reply with quote

To store a 1kbyte table, starting at 0xc00 on a pic18f452...

#org 0xC00
#rom 12,20,20,30,50,50...

How can we continue the table in the next line to format like 16x64 cells?

Being a 16bit program memory, will it be stored using all memory bytes or it will be right justified and the rest filled with 0's?

xxxxxxxx xxxxxxxx total width
00000000 00001100 "12"
00000000 00010100 "20"

or

xxxxxxxx xxxxxxxx total width
00001100 00010100 "12" "20"

?
Ttelmah
Guest







PostPosted: Thu May 27, 2004 2:17 am     Reply with quote

future wrote:
To store a 1kbyte table, starting at 0xc00 on a pic18f452...

#org 0xC00
#rom 12,20,20,30,50,50...

How can we continue the table in the next line to format like 16x64 cells?

Being a 16bit program memory, will it be stored using all memory bytes or it will be right justified and the rest filled with 0's?

xxxxxxxx xxxxxxxx total width
00000000 00001100 "12"
00000000 00010100 "20"

or

xxxxxxxx xxxxxxxx total width
00001100 00010100 "12" "20"

?

Just keep going.
So:
#rom 0x3000 = {
01,02,03,04,
05,06,07,08,
09,0A,0B,0C
}

On the 16bit chips, each number by default holds a 16bit value. However you can add a 'int8' statement to the ROM declaration, so that 8bit values are stored, and use a declaration like:
#ROM int8 0x3000 = etc.

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