Out of Memory
Z-World, Inc. / Rabbit Semiconductor Tech Bulletin Board:
Rabbit-Based Products:
FAQs and Knowledge Base:
Dynamic C:
Dynamic C Software:
Out of Memory
How do I increase Root Code or Root Data allocation?
Please keep in mind the following about the Rabbit 2000:
(1) it is an 8 bit processor
(2) with a 16 bit program counter
(3) and a 20 bit address bus
The following discussion applies only if Separate Instruction and Data is NOT enabled.
As such it must use memory management techniques to access memory above 64 KB. Dynamic C utilizes the 64KB "root" memory as follows:
(1) about 24 KB for Root Code, with about 10 KB needed by the BIOS,
(2) about 28 KB for Root Data, some of which is needed by various Dynamic C libraries
(3) 4 KB for the stack,
(4) and 8 KB for the xmem window.
The "out of Code space" error can be corrected by any of several means:
(a) declare some of your functions to be in xmem - see the Dynamic C manual
(b) tell the compiler to put many functions into xmem by using the #memmap directive - see the Dynamic C manual
(c) modify the BIOS to increase the value of DATAORG - for each 0x1000 increase you will gain 4KB for your program with a corresponding 4KB reduction in the Root Data area for variables. This option is only valid with Seperate Instruction and Data Space DISABLED!
Pure assembly functions go to root. Pure assembly functions may be forced into xmem by using the following: #asm xmem
Remember that all initialized constants - including strings - are stored in Root Code (in flash). If you have large initialized data arrays or strings, try moving them to xdata. xdata cannot be addressed directly with a pointer, so this may require some recoding to use xmem2root().
Out of Root Data - You can use xalloc, root2xmem and xmem2root. These allow you to create areas of RAM in extended memory and to copy data to and from them. You can also use the LDP instructions in assembly language which allow you to directly access the entire 20 bit address space. Another option is to edit the BIOS file as in (c) above but to reduce the value of DATAORG. Each 0x1000 decrease in its value will increase Root Data by 4K but also decrease Root Code by 4K.
The sample program MEMORY_USAGE.C will display a table of how memory is allocated in a Dynamic C program.
Here is a link to a Technical Note: Root Memory Usage Reduction tips
MEMORY_USAGE.C
I have received several requests for the program. Please be aware that it requires at least version 7.0 of Dynamic C.
Memory_usage program -
The MemoryUsage sample program will display on STDIO a fairly detailed description of the memory in your Rabbit-based product. However, it currently only detects the primary flash. This is the case for Dynamic C up to and including 7.20.