PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Dec 27, 2005 11:45 am |
|
|
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 |
|
|