Automatic variable usage

I understand that especially for global variables, it is important to consider using XDATA whenever speed isn’t critical, since there is so much more of it available. But what about ordinary “auto” variables within a function. I would think these go on the stack, and so probably can be declared without any CPU specific storage class. Yet it seems I’ve seen many examples of wixel functions where ordinary non-static auto variables are still declared as XDATA within a function. Is this really necessary?

I guess I got my answer, because not declaring variables as XDATA eventually did cause me linker errors, for exceeding the fast RAM area. But while I expected that for global data, I’m honestly still unsure about variables declared within a function. I understand that static vars have to be properly declared as XDATA to avoid using up fast RAM, because static vars have to persist. But what about “auto” variables within a function? Aren’t these stack based, and placed in XDATA space by default?


For the Wixel, we are using SDCC’s “medium” memory model, which means that local variables in a function will be stored in a static location in PDATA by default. PDATA is basically the first 256 bytes of XDATA, and it can be accessed more quickly than XDATA because the compiler sets the MPAGE register to always point to PDATA. PDATA is different from the stack, but the compiler still uses stack space to store the values of registers. The stack is not in XDATA.

I did a quick review of the apps that have local variables stored in XDATA. It looks like all of those variables were for buffers of data. Storing them in XDATA makes it less likely that the linker will run out of PDATA space and it makes it easier to create an XDATA pointer to the buffer. A lot of Wixel functions require an XDATA pointer as an argument. The CC2511F32 is special because all of RAM is accessible from XDATA pointers, but SDCC does not know that, so it is difficult to use a PDATA pointer as an XDATA pointer.


Thanks! So now that I understand that auto variables can take up valuable PDATA memory, I’ll be more aware of that. Just a minor inconvenience. My application has grown pretty large and complex, and these details are starting to count. In any case, this The CC2511F32 chip continues to amaze me, with all I’ve gotten it to do over the past couple of years.