The #pragma memory RAM directives in the Device Header File describe to the compiler where RAM is available for allocating variables. Several #pragma memory RAM directives are required, because either the RAM is not contiguous, or is accessed in different ways. Variables are placed in the RAM areas starting from the area specified by the first #pragma memory RAM directive.
Use the listing file to determine where the compiler has allocated a variable.
Figure 5-1. determining the variable address var1.lst
#pragma option RAMMAP
0008 0010 unsigned int arr[16]; /* 0x10 bytes at address 0x008 */
void main(void)
{
077F unsigned int i; /* allocated at address 0x7ff */
0200 DF 07 LD S,#007 for(i=0;i<sizeof(arr);i++)
0202 BC 7F 00 LD 077F,#00
{
0205 DF 07 LD S,#007 arr[i]=i;
0207 9D 7F LD A,077F
0209 94 08 ADD A,#008
020B 9C FC X A,X
020D 9D 7F LD A,077F
020F DF 00 LD S,#000
0211 B6 X A,[X]
}
0212 9F 7F LD B,#07F
0214 DF 07 LD S,#007
0216 A6 X A,[B]
0217 8A INCA
0218 A6 X A,[B]
0219 98 10 LD A,#010
021B 83 IFGT A,[B]
021C E8 JP 00205
021D FF JP 0021D while(1);
}
The declaration in the listing file will show the address of the variable in the left column. The symbol table entry will list the address of all global variables. If the RAM usage map is enabled with the #pragma option RAMMAP directive, then the listing file will contain the address, type and scope of all variables.
Figure 5-2. the RAM USAGE MAP var1.lst
RAM USAGE MAP
0000 __longIX signed long
0002 __longAC signed long
00FE BREG unsigned char
00FC X portrw
00FD SP portrw
00FE B portrw
00FF S portrw
0090 PORTE portrw
0090 PORTED portrw
0091 PORTEC portrw
0092 PORTEP portr
0094 PORTF portrw
0094 PORTFD portrw
0095 PORTFC portrw
0096 PORTFP portr
00A0 PORTA portrw
00A0 PORTAD portrw
00A1 PORTAC portrw
00A2 PORTAP portr
00A4 PORTB portrw
00A4 PORTBD portrw
00A5 PORTBC portrw
00A6 PORTBP portr
00AD TINTA portr
00AE TINTB portr
00AF HSTCR portrw
00D0 PORTL portrw
00D0 PORTLD portrw
00D1 PORTLC portrw
00D2 PORTLP portr
00D4 PORTG portrw
00D4 PORTGD portrw
00D5 PORTGC portrw
00D6 PORTGP portr
00D8 PORTC portrw
00D8 PORTCD portrw
00D9 PORTCC portrw
00DA PORTCP portr
00DC PORTD portrw
00DC PORTDD portrw
00EE CNTRL portrw
00EF PSW portrw
00E8 ICNTRL portrw
00EA TMRLO portrw
00EB TMRHI portrw
00EC T1RALO portrw
00ED T1RAHI portrw
00E6 T1RBLO portrw
00E7 T1RBHI portrw
00C6 T2CNTRL portrw
00C0 TMR2LO portrw
00C1 TMR2HI portrw
00C2 T2RALO portrw
00C3 T2RAHI portrw
00C4 T2RBLO portrw
00C5 T2RBHI portrw
00B6 T3CNTRL portrw
00B0 TMR3LO portrw
00B1 TMR3HI portrw
00B2 T3RALO portrw
00B3 T3RAHI portrw
00B4 T3RBLO portrw
00B5 T3RBHI portrw
00E9 SIOR portrw
00CF ITMR portrw
00CB ENAD portrw
00CD ADRSLTL portrw
00CC ADRSLTH portrw
00A8 ISPAD portrw
00A8 ISPADLO portrw
00A9 ISPADHI portrw
00AA ISPRD portrw
00AB ISPWR portrw
00E1 PGMTIM portrw
00E2 ISPKEY portrw
00B8 TBUF portrw
00B9 RBUF portrw
00BA ENU portrw
00BB ENUR portrw
00BC ENUI portrw
00BD BAUD portrw
00BE PSR portrw
00C7 WDSVR portrw
00C8 LWKEDG portrw
00C9 LWKEN portrw
00CA LWKPND portrw
0008 arr unsigned char[16]
077F i unsigned char 0200 021D
The RAM map has four columns. Each line of the RAM usage map contains the variable's address, name and type. If the variable has local scoping, the address range in which the variable is valid is also listed.