Discussion in "8051 Discussion Forum" started by    scorcho    Oct 9, 2007.
Tue Oct 09 2007, 04:56 AM

I'm wondering what the difference is when I declare a variable with one of the modifiers, eg

1. BYTE xdata temp;
2. BYTE idata temp;
3. BYTE data temp;
4. BYTE temp;

I notice that some data types aren't allowed to be placed in xdata, for example BOOL. I get an error telling me it's in a different/illegal memory space.

I also notice that there are code size differences. When I put variables in xdata/idata(1/2), my code seems to be larger by a few bytes than if I were to put them in data or not specify them(3/4). I'm wondering if there are any functional differences. I'm trying to keep my code as small as possible now so should I not put anything in xdata/idata? What are the guidelines?

btw I'm programming in C and using Keil uVision2 as my IDE.

Tue Oct 09 2007, 11:08 AM
Xdata doesn't allow BOOL the reason is external RAM is byte oriented and is not accessible bit wise.

Regarding the reason of increase in code space when u put variables in xdata/idata is that when you declare a variable and initialize it... the whole initialization code as well as creating a data space for that variable is generated as a code.
Like if you declare something like...
BYTE idata a[10] = "test";
when you compile this, the compiler generate a code which includes the code for creating a variable of 10 bytes in idata and then initialize it with string "test" So this increase your code.. there is actually nothing can be done regarding this..
The only optimization tip i can give you is.. if you have constant strings, which are not going to change throughout the program then its better to store them in the code space instead of idata/xdata.. e.g.

BYTE code string[]="Welcome to Rickey's World";

this will take no space in RAM and will save the initialization part and ultimately the code space..
Tue Oct 09 2007, 05:39 PM
u can also refer c51.pdf for more ... of the topic...

Get Social


Powered by e107 Forum System


Mon Mar 01 2021, 10:00 PM
Olivia Johnson
Citibank expects Bitcoin to hit USD$300,000 by end of this year.



Thu Jun 25 2020, 03:46 PM
Mon Jun 22 2020, 03:03 PM
Tue Jun 16 2020, 05:10 PM
Sat Jun 13 2020, 09:43 PM
Thu May 21 2020, 12:44 PM
Thu May 21 2020, 01:28 AM
Wed May 20 2020, 07:05 PM
Wed May 20 2020, 11:52 AM


Guests: 97, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38215
Newest member: Mirza123