We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Where is the xdata stored and where is code stored?
The Problem that I am facing is , when I do
unsigned char xdata buff[300]; void func() { ........... ..... .. }
the results of running this application suggests that xdata buff has overwritten the function func.
The Map file shows the following addresses * * * * * * * X D A T A M E M O R Y ** * * * * * XDATA 0000H 012CH UNIT ?XD?DEMO XDATA 012CH 000AH UNIT _XDATA_GROUP_
* * * * * * * C O D E M E M O R Y * * * * * * * CODE 0000H 0003H ABSOLUTE 0003H 00FDH *** GAP *** CODE 0100H 03C7H UNIT ?PR?_FUNC?DEMO CODE 04C7H 0131H UNIT ?C_INITSEG
Which shows the base addresses of XD?DEMO of 300 bytes and the function func to be the same !!!
Also in the code segment, a gap of 256 bytes has been left before the function func. Hence if the xdata buff size is kept 256 bytes, there is no problem. Only when I exceed this limit , there are problems.
Let me know where is xdata stored and where is the code segment? Are they overlapping? How can I declare an external data buffer of 300 bytes?
Regards, Gaurav
xdata and code are different memory spaces. Unless your chip provides some sort of mapping mechanism (i.e. it can map xdata space into code space or vice versa), the two memory spaces are completely separate.
The '51 processor even uses different instructions to access the different memory spaces.
modifying my question Say you declare some xdata and define some code when you compile this, in the resultant image, in which address locations will xdata and the code be placed.
As I mentioned earlier, in my case it is showing xdata starting from 0000H and the code also starting from 0000H.
In my application, both xdata and the code are placed in the same memory.
As Christoph says, XDATA and CODE are completely independent address spaces!
There are also PDATA, DATA, and IDATA...
You need to do some basic study on the 8051 architecture; eg, by reading the so-called "bible" for the 8051:
Chapter 1 - 80C51 Family Architecture: www.nxp.com/.../80C51_FAM_ARCH_1.pdf
Chapter 2 - 80C51 Family Programmer's Guide and Instruction Set: www.nxp.com/.../80C51_FAM_PROG_GUIDE_1.pdf
Chapter 3 - 80C51 Family Hardware Description: www.nxp.com/.../80C51_FAM_HARDWARE_1.pdf
And, for details of how Keil C51 supports all this, see: http://www.keil.com/support/man/docs/c51/c51_le_memareas.htm
http://www.keil.com/support/man/docs/c51/c51_le_memtypes.htm
"As I mentioned earlier, in my case it is showing xdata starting from 0000H and the code also starting from 0000H."
You should think of those as "relative" addresses; The "fully-qualified" addresses would be, in Keil notation, X:0000H and C:0000H
OK... it is fine if they are relative addresses. Just that I am facing a problem when I increase my xdata size to more than 256..and i see that 256 bytes of code is as a gap in the code segment and the function starts from 257th location. So I thot maybe the data is corrupting the code when I increase it beyond 256 bytes. Thanks a lot for the prompt replies. Let me know if you have anything more to tell me that will help me resolve the problem Regards, Gaurav
"Let me know if you have anything more to tell me that will help me resolve the problem"
As already noted, you really need to do that basic study on the 8051 architecture, and the Keil tools - you need to get these foundations good & solid before you start trying to build your grand edifice...
"it is fine if they are relative addresses"
I said you should think of them as "relative" (in quotes) addresses - be careful not to read too much into that!
Again, you really need to study those documents to really understand what's going on...
Your hardware maps both xdata and code space to the same physical memory - is that what you mean ?
This is a very unusual memory configuration, since for the '51 chip itself, code and xdata are completely separate memory areas.