This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

xdata and data segment

Hello,

Could using xdata or ram able to change the behavior of the code in C?

I am just wondering when I use xdata i in a for loop (i=0; i<100; i++) compared to data, I would get timing different between this two data segment.

Can anyone advise when is the right time to use xdata or ram data?

I am run out of ram data, when i try to use xdata in some function, compilation works fine, but the I2C function doesn't work as expected anymore.

  • Of course you get different timing when having different memory accesses. You also get different timing if you switch to another compiler, or different compiler options.

    That is why delay loops should not be formed by busy-loops that doesn't look at some hardware-driven state information when counting the time. Or why the sw loop should be written in assembler where you can know the required cycle count for the individual instructions.

    DATA or XDATA? That depends on need.

    If parts of the code is speed-critical, then DATA.
    If you need to conserve code space - then most used variables in DATA.
    XDATA for "garbage-collect" of non-critical data.

  • It takes a lot more ASM Instructions to read and Write to XDATA as Compared to DATA. That is a limitation of the 8052.

  • But there can be a lot more of it!