Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

Important Points in 8051 Programming 8051 Data Memory Architecture

The document discusses the complex memory architecture of the 8051 microcontroller and how to optimize code efficiency when programming for it using IAR Embedded Workbench. It describes the internal data memory space which is divided into data, idata, bdata/bit, and sfr areas. The external data memory space includes pdata, ixdata, and xdata_ROM areas. It recommends placing frequently accessed variables in data area and arrays in external memory for efficiency. When writing C code, a memory model must be specified which determines where data and pointers are stored. Memory modifiers like __data and __idata are used to declare variables in specific memory areas.

Uploaded by

Nono
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Important Points in 8051 Programming 8051 Data Memory Architecture

The document discusses the complex memory architecture of the 8051 microcontroller and how to optimize code efficiency when programming for it using IAR Embedded Workbench. It describes the internal data memory space which is divided into data, idata, bdata/bit, and sfr areas. The external data memory space includes pdata, ixdata, and xdata_ROM areas. It recommends placing frequently accessed variables in data area and arrays in external memory for efficiency. When writing C code, a memory model must be specified which determines where data and pointers are stored. Memory modifiers like __data and __idata are used to declare variables in specific memory areas.

Uploaded by

Nono
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

by Kota Mogi, IAR Systems

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


Internal data memory space is a space whose address is 8-bit addressable using 0-0xFF, as shown in
the drawing below, consisting of two parts: one is memory, the other I/O (sfr – Special Function
Register.)

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.

External data memory space


External data memory space is a memory that is essentially connected to the outside of a
microcontroller, but some of the recent microcontrollers have it inside. Areas located higher than
address 0x10000 are called Extended memory. However, not all 8051 devices have Extended memory.

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

How to write code in C language


When compiling, one of the five memory models are used. The memory model specifies what part of
memory to be used for data and data pointers. If you specify one of the models in the project option
according the system being developed, it’ll save you the trouble of designating the location to store the
memory for the variable.

Data Model Default data memory attribute Default data pointer

Tiny __data __idata

Small __idata __idata

Large __xdata __xdata

Generic __xdata __generic

Far __far __far

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.

data area __data


idata area __idata
bit area __bit
:
:

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.

You might also like