Back to ESAcademy Home Page


www.philipsmcu.com8051 Memory Configuartions with C Compilers

by Andy Ayre, ESAcademy
based on the C51Primer, by Mike Beach, Hitex UK

The Keil and Raisonance C Compilers provide a variety of memory models. When do we choose which model?

[ Introduction | Available memory models | Choosing a model | Using a model ]

 

Home

News

Training Classes

Products

Consulting

Technical Library

Contact Us

Recommended Books

Possible Memory Models

With a microcontroller like the 8051, the first decision is which memory model to use. Whereas the PC programmer chooses between TINY, SMALL, MEDIUM, COMPACT, LARGE and HUGE to control how the processor segmentation of the RAM is to be used (overcome!), the 8051 user has to decide where the program and data are to reside.

The Keil and Raisonance compilers currently support the following memory configurations:

  1. ROM: currently the largest single object file that can be produced is 64K, although up to 1MB (Keil Compiler) or 4MB (Raisonance Compiler) can be supported with the BANKED model described below. All compiler output to be directed to ROM, constants, look-up tables etc., should be declared as "code".
  2. RAM: There are three memory models, SMALL, COMPACT and LARGE
    • SMALL: all variables and parameter-passing segments will be placed in the 8051's internal memory.
    • COMPACT: variables are stored in paged memory addressed by ports 0 and 2. Indirect addressing opcodes are used. On-chip registers are still used for locals and parameters.
    • LARGE: variables etc. are placed in external memory addressed by @DPTR. On-chip registers are still used for locals and parameters.
  3. BANKED: Code can occupy up to 1MB (Keil Compiler) or 4MB (Raisonance Compiler) by using either CPU port pins or memory-mapped latches to page memory above 0FFFFH. Within each 64KB memory block a COMMON area must be set aside for C library code. Inter-bank function calls are possible.

In addition, the Raisonance Compiler provides a TINY memory model, which is identical to the SMALL memory model, except that ACALL and AJMP instructions are generated rather than LCALL and LJMP. This limits the code size to 2K bytes and is useful for those devices that do not support the LCALL and LJMP instructions. However when considering memory spaces the TINY and SMALL memory models are identical.

A variation on these models is to use one model globally and then to force certain variables and data objects into other memory spaces.

[ Introduction | Available memory models | Choosing a model | Using a model ]