Hi. I m facing a problem regarding data reading from one memory to another via pointer. I am using LARGE memory model for ROM & RAM. I defined one function in idata as below: unsigned char func1(void) small { unsigned char status; unsigned char xdata *pSrc; unsigned char *pDst; pSrc = (unsigned char xdata *) &Obj_Xdata; pDst = (unsigned char idata *) &status; *pSrc = *pDst; } here, Obj_Xdata is a 1 byte data located in XDATA. But writting the code as above, i m not able to get the proper value of Obj_Xdata in the status variable. Please suggest the way to achive this.
Hi henry.. Thanks for suggestion. But i have modified as below: unsigned char func1(void) small { unsigned char status; unsigned char *pSrc; unsigned char *pDst; pSrc = (unsigned char xdata *) &Obj_Xdata; pDst = (unsigned char idata *) &status; *pDst = *pSrc; } Now, this is working. I think both pointer should be generic inorder to have correct value.
No, it should not be necessary for both pointers to be generic for this to work. The real mistake in your original code was that you had the assignment backwards. But your code is still quite unreasonable:
pSrc = (unsigned char xdata *) &Obj_Xdata; pDst = (unsigned char idata *) &status;
Hi Hans. Thanks for the suggestion, actually i m reading a 32-bit data from XRAM which is slower type, so i have to perform clock stretching, so i m reading total 4 bytes using a pointer. Well i m still not able to understand this. The function is defined for idata, so status will be stored in idata only and pDst is generic pointer, so the statement: "pDst = (unsigned char idata *) &status;" should be reasonable. As generic pointer can be casted to any type. Now, my 32-bit data Obj_Xdata is in XRAM, so i created memory-specific pointer pSrc for XRAM to reduced the pointer size to 2 bytes. So the statement: "pSrc = (unsigned char xdata *) &Obj_Xdata;" should be reasonable. Still there is some problem that i m not able to find out ..!! Guide me ..!! Thanks in advance.
There are several separate issues here: 1) you're going through all those explicitly constructed pointers, without any demonstrated need to for most of them. As I said, all that pointer gymnastics is equivalent to a plain and simple assignment
status = Obj_Xdata;
unsigned char xdata * pSrc = &Obj_Xdata; status = *pSrc;