Memory Models
The memory model determines the default memory type to use for function arguments, automatic variables, and declarations that include no explicit memory type.
The mikroPascal PRO for 8051 provides three memory models:
You may also specify the memory model on a function-by-function basis by adding the memory model to the function declaration.
Small memory model generates the fastest, most efficient code. This is default memory model. You may override the default memory type imposed by the memory model by explicitly declaring a variable with a memory type specifier.
Small model
In this model, all variables, by default, reside in the internal data memory of the 8051 system—as if they were declared explicitly using the data
memory type specifier.
In this memory model, variable access is very efficient. However, all objects (that are not explicitly located in another memory area) and the call stack must fit into the internal RAM.
Call Stack size is critical because the stack space used depends on the nesting depth of the various functions.
Compact model
Using the compact model, by default, all variables are allocated in a single page 256 bytes of external data memory of the 8051 system—as if they were explicitly declared using the pdata
memory type specifier. This memory model can accommodate a maximum of 256 bytes of variables. The limitation is due to the addressing scheme used which is indirect through registers R0 and R1 (@R0, @R1). This memory model is not as efficient as the small model and variable access is not as fast. However, the compact model is faster than the large model.
mikroPascal PRO for 8051 uses the @R0 and @R1 operands to access external memory with instructions that use 8 bit wide pointers and provide only the low-order byte of the address.
The high-order address byte (or page) is provided by Port 2 on most 8051 derivatives (see datasheet for details).
Large model
In the large model all variables reside in external data memory (which may be up to 64K Bytes).
This is the same as if they were explicitly declared using the xdata
memory type specifier.
The DPTR is used to address external memory.
Instruction set is not optimized for this memory model(access to external memory) so it neeeds more code than the small or compact model to manipulate with the variables.
function xadd(a1 : byte; a2 : byte) : byte; large; // allocate parameters and local variables in xdata space begin result := a1+a2; end;
What do you think about this topic ? Send us feedback!