Discussion in "8051 Discussion Forum" started by    scorcho    Oct 9, 2007.
Tue Oct 09 2007, 10:26 am
#1
Hi,

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.

Thanks.
Tue Oct 09 2007, 04:38 pm
#2
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, 11:09 pm
#3
u can also refer c51.pdf for more ... of the topic...

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm
Bernardwarge
Tue Mar 26 2024, 11:15 am