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

Constant Data Table in ROM- 2 Dimensions?

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 27, 2005 11:45 am     Reply with quote

Quote:
I tried printing out the .hex file and disassembly listing, but i couldn't find any pattern of "1,2,3,4,5,6" anywhere in it.

The compiler will only put the const array into ROM if you put in
a line of C code to access the array. Even then, if you access the
array with constant indexes (such as table[0][0]), the compiler
will optimize that fetch into a MOVLW statement and it won't put the
entire array into ROM. If you want to see the entire array put
into ROM, you must use a variable for at least one of the indexes.
Then edit the .H file for your PIC, and comment out the #nolist
statement at the top. Re-compile and look at the .LST file.

Example:
Code:
#include <18F452.h> 
#fuses XT,NOWDT,NOPROTECT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

int const table[4][3] = {{1,2,3}, {4,5,6}, {7,8,9}, {0xa, 0xb, 0xc}};

//=============================
void main()
{
int8 x;
int8 i;

x = table[i][0];   // Use a variable for one of the indexes

while(1);
}


Here is the top part of the .LST file for the program above.
Code:
0000:  GOTO   0020
.... #include <18F452.h>   
.... /// Standard Header file for the PIC18F452 device ////
.... #device PIC18F452
0004:  CLRF   FF7
0006:  ADDLW  14
0008:  MOVWF  FF6
000A:  MOVLW  00
000C:  ADDWFC FF7,F
000E:  TBLRD*+
0010:  MOVF   FF5,W
0012:  RETURN 0
0014:  DATA 01,02      // Here is the array data.
0016:  DATA 03,04
0018:  DATA 05,06
001A:  DATA 07,08
001C:  DATA 09,0A
001E:  DATA 0B,0C
.................... //#nolist
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