|
|
|||||||||
Choosing The Best Memory Configuration/ModelWith the three memory models, a decision has to be made as to which one to use. Single chip 8051 users may only use the SMALL model, unless they have an external RAM fitted which can be page addressed from Port 0 and optionally, Port 2, using MOVX A,@R0 addressing. This permits the COMPACT model. While it is possible to change the global memory model half way through a project, it is not recommended! SMALL: Total RAM 128 bytesUsing this memory model, the number of global variables must be kept to a minimum to allow the linker's OVERLAY function to work to best effect. With 8052/32 versions, the manual use of the 128 byte IDATA area above 80H can allow applications additional variable storage space, however the amount of space required for the stack must be kept in mind. The SMALL model can support very large programs by manually forcing large and/or slow data objects in to an external RAM, if fitted. Also variables that need to be viewed in real time are best located here, as dual-ported emulators (like the ones from Hitex and Raisonance) can read their values on the fly. This approach is generally best for large, time-critical applications, as the SMALL global model guarantees that local variables and function parameters will have the fastest access, while large arrays can be located off-chip. COMPACT: Total RAM 256 bytes off-chip, 128 or 256 bytes on-chip.Suitable for programs where, for example, the on-chip memory is applied to an operating system. The compact model is rarely used for an entire program, but more usual in combination with the SMALL switch reserved for interrupt routines. COMPACT is especially useful for programs with a large number of medium speed 8 bit variables, for which the MOVX A,@R0 is very suitable. It can be useful in applications where stack usage is very high, meaning that data needs to be off-chip. Note that register variables are still used, so the loss of speed will not be significant in situations where only a small number of local variables and/or passed parameters are used. LARGE: Total RAM up to 64KB, 128 or 256 bytes on-chip.Permits slow access to a very large memory space and is perhaps the
easiest model to use. Again, not often used for an entire program, but in combination with
SMALL. As with COMPACT, register variables are still used and so efficiency remains
reasonable. Here are some recommendations for the best use of each: DATA: 128 bytes; SMALL model default location Best For: Worst For: IDATA; 128 bytes or 256 bytes; Not model-dependant Best For: Worst For: CODE: 64K bytes Best For: Worst For: PDATA: 256 bytes; COMPACT model default area Best For: Worst For: XDATA; up to 64K bytes; LARGE model default area Best For: Worst For: [ Introduction | Available memory models | Choosing a model | Using a model ] |