Memory Allocation Clause Samples

Memory Allocation. In the VM mode, the memory is divided into two parts: internal and external RAM. The internal RAM totals 256 bytes while the external RAM is up to 2K bytes. Some compilers might use the internal RAM as stack in their compilation results, so under normal circumstances, try as much as possible to use the external RAM in case the memory may overflow. In the codes, the internal RAM and external RAM are identified respectively by keyword idata and xdata. For example: xdata unsigned long x; idata unsigned long i; The variable x is defined in the external RAM while the variable i is defined in the internal RAM. You do not need always to define variables explicitly using these two keywords. The compiler can use the default value. For instance, if the compilation mode is set to Large (which is recommended by us), all the variables without being given a special declaration will be defined in the external RAM. In this case, to define variables in the internal RAM requires that the keyword idata should be used explicitly. The XA mode does not differentiate internal RAM from external RAM. The communication buffer is a special memory. Under VM mode and XA mode, there is difference in the memory address of the communication buffer. The memory structure is shown in Figure 4-1: 0 …………………. 0xFF 0 …………………… 0x7FF 0x800 0x8001 0x8FA Internal RAM External RAM Data length Communication buffer a. VM Mode Memory Structure 0 ……………………………………………0x7FF invalid 0x1000 0x1001. 0x10FA RAM Data length Communication buffer