Important Points in 8051 Programming 8051 Data Memory Architecture
Important Points in 8051 Programming 8051 Data Memory Architecture
8051 is an old microcontroller released by Intel in 1980. After its release several semiconductor vendors
started offering 8051-based microcontrollers, and it is still widely used with a variety of
improvements/enhancements made to it. While it’s designed to improve efficiency considerably when
programming in assembler, many instances have been observed where it’s challenging to program in
standard C language in terms of memory capacity, without taking special consideration. On the other
hand, IAR Embedded Workbench for 8051 supports a wide range of devices for 8051 core, and can
generate in the standard C language code comparable to what is written in the assembler.
The purpose of this article is to discuss some of 8051’s complex memory architecture in order to utilize
code efficiency offered by IAR Embedded Workbench, making the most out of its features.
Internal data memory space is further divided into four different parts: data, idata, bdata/bit, and sfr,
some of which are overlapping.
data (0x00-0x7F)
An area that can be accessed via direct addressing of the assembler instructions.
idata (0x00-0xFF)
An area accessible via register indirect addressing of the assembler instructions.
bdata/bit (0x20-0x2F)
An area that can be accessed bit by bit. The size of the area is 16 bytes and can store 128 bool type
variables in C language. bdata can access bitwise data in the unit of 8 bit. This enables it to set/clear
multiple bits with one instruction at once.
Page 2
sfr (0x80-0xFF)
I/O area. It overlaps with the above memory areas; which one of them to be accessed depends on the
assembler instruction you use. However, you do not need to be aware which one to access as long as
you’re writing C source code for IAR Embedded Workbench.
As with Internal data memory space, it has three areas, pdata, ixdata, and xdata_ROM overlapping but
we’ll skip the details here. Worth mentioning is however that ixdata, if available, and pdata access
external memory more efficiently. Because external data memory space can only be accessed via the
assembler instruction, movx, the procedure that accesses certain variables is lengthy; placing
frequently-accessed variables in this area will generate inefficient code.
Therefore, the overall efficiency improves when you place scratch memory and index for an array in the
data area, and locate the array itself in the external data memory space. Since the data area is
extremely small, you have no choice but to use idata for large programs. If idata is still not sufficient,
you can choose the areas pdata, ixdata, ixdata, and far/huge as the program size increases.
Page 3
Before declaring variables in C language, specify the area to place them using a memory modifier
prefixed with “__” as follows:
__idata int i, j;
int __idata k, l;
Either of the above declarations is valid. The names of the data areas mentioned above, prefixed with
two underscores, are the memory modifiers that correspond to the memory spaces described earlier, to
be written either right or left of the data type that declares the memory.
Conclusion
Even though 8051 is an architecture that has been on the market for almost thirty years, it is still widely
adopted in newly developed microcontrollers as well as SoCs. IAR Embedded Workbench is constantly
evolving as well. With IAR Embedded Workbench, in addition to the data memory model, other options
such as code memory model and calling conventions can be specified, allowing for full utilization of
8051’s capabilities.