Page 1 of 1

Rom constant address question - answered

Posted: 14 Jun 2011 18:29
by Dany
Hi, I see a difference in constant address between the content of a pointer to it and what the statistics "rom memory constants" show.

This is the code (that fully works by the way):

Code: Select all

program Const_Pointer_Test;

const WrdArr: array[10] of word = (1000,2000,3000,4000,5000,6000,7,8,9,0);
var Ptr: ^const word;
var   Wrd: word;

begin
  { Main program }
  Ptr := @WrdArr;      // <---------------- Ptr has a value of 0x822C (seen in the debugger)
  Wrd := Ptr^;                
  inc(Ptr);
  Wrd := Ptr^;
  inc(Ptr);
  Wrd := Ptr^;
end.
After the first instruction has been executed (see arrow), Ptr contains the address of constant "WrdArr".
The content of Ptr is then (seen in the debugger) 0x822C.
But: in the statistics screen the address of "WrdArr" seems to be 0x022C.
The list file shows also an address of 0x022C.

Do I miss something? (I am new to PIC24...)

Thanks in advance!

Re: Rom constant address question

Posted: 15 Jun 2011 10:33
by slavisa.zlatanovic
Hi Danny!

Please, see the MCU datasheet: READING DATA FROM PROGRAM MEMORY USING PROGRAM SPACE VISIBILITY.
PSV.PNG
PSV.PNG (49.06 KiB) Viewed 3153 times
Note how the address is formed: PSVPAG + 1(MSB) + EA[14:0].
In the Statistic Window you see the real address of the const WrdArr and in the Watch Window you see the value of the
pointer 1(MSB) + EA[14:0].

Re: Rom constant address question

Posted: 15 Jun 2011 10:58
by Dany
Aha! Thanks! :D :D :D :D