C51 Compiler - Language Extension (1) - Memory Model and Storage Types

Publisher:bln898Latest update time:2016-11-14 Source: eefocusKeywords:C51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Cx51 extends ANSI standard C. Most of these extensions are to support the architecture of 8051 systems. These extensions are:

Memory types and regions on 8051

Memory model

l Memory type indication

l Variable type indication

l Bit variables and bit-addressable data

l Special Function Registers

Pointer

Function attributes

Keywords

_at_

alien

bdata

bit

code

compact

data

idata

interrupt

large

pdata

_priority_

reentrant

sbit

sfr

sfr16

small

_task_

using

xdata

You can disable the use of these extensions with the NOEXTEND control directive

8051 Memory Areas

The 8051 architecture supports a number of physically separate memory areas or spaces for data and programs. Each memory area has its advantages and disadvantages. Some areas are readable but not writable, some are both readable and writable, and some are read and written much faster than others. This variety of memory spaces is different from mainframes, minicomputers, and microcomputers that place all data, programs, and constants in the same physical space within the computer.

Program Memory

Program memory is read-only memory and cannot be written to. Depending on the variant and hardware design of 8051, program memory can be internal to the 8051 CPU, external to it, or both. Program memory can be up to 64K bytes. Program code including all functions and runtime libraries are placed in program memory. Constants can also be placed in program memory. 8051 only executes programs that are placed in program memory.

In Cx51, program memory can be accessed through CODE type instructions

Internal Data Memory

Internal data storage exists inside the 8051 CPU and can be read and written. Depending on the 8015 variant, this internal data storage can be up to 256 bytes. The first 128 bytes can be addressed directly or indirectly. The next 128 bytes can only be accessed indirectly. The 16 bytes starting at 20h are bit addressable.

Since the internal data memory can be accessed using an 8-bit address, accessing the internal data memory is very fast. However, the internal data memory is only 256 bytes.

Using Cx51, the internal data memory can be divided into three different data types: data, xdata and bdata

The Data memory pointer refers only to the first 128 bytes of the internal data memory. Data placed in this area is accessed using direct addressing.

Idata refers to all 256 bytes of internal data memory; however, data placed in this area is accessed through indirect addressing, which is slightly slower than direct addressing.

Bdata refers to the 16-byte bit-addressable space starting from 20h. This area can declare bit-addressable data.

External Data Memory

(slightly)

Special Function Register Memory

(slightly)

Memory Models

The memory model determines the default memory type for function parameters, automatic variables, and variables without a declared memory type.

Note: Except for very special applications, use SMALL memory type. This will generate code that runs faster and more efficiently.

Small Model

In this mode, all variables are placed in the internal data memory area of ​​8051 by default. Data access efficiency is very high in this mode. However, the stack is also placed in the internal RAM, so the stack size requirement is very demanding. If the linker/compiler is configured to overwrite the internal data memory, then this mode is the best choice.

Compact Model

In this mode, all variables are placed in the first page of the external data memory. 256 bytes of variables can be stored in this mode. The limitation of this mode comes from its addressing method, which uses registers R0 and R1 for addressing. This mode is not as efficient as small mode, and variable access is not as fast. But this mode is faster than large mode.

When using compact mode, Cx51 uses @R0 and @R1 to access external data memory. If you want to access external data memory higher than 256 bytes, the high byte can be provided through Port 2. In this case, you must correctly initialize Port2 to the correct page number of the external data memory. This can be done in the startup code. You must also specify the starting address of PDATA for the connector.

Large Model

In large mode, all variables are placed in an external data memory area (up to 64K bytes). The data pointer (DPTR) is used for addressing. Memory access through this data pointer is inefficient, especially for variables with a data size greater than 2 bytes. This access method generates more code than small and compact methods.

Memory Types

The Cx51 compiler explicitly supports the 8051 architecture and base variants, and provides access to all 8051 memory areas. Each variable can be explicitly assigned to a specific memory space.

Explicitly Declared Memory Types

You can specify the storage area for a variable by including a memory type identifier in its declaration.

 

type

 

describe

 

code

 

Data memory (64K bytes), accessed by movc @a+dptr

 

data

 

Directly addressable internal data memory, fastest addressing of variables

 

idata

 

Indirect addressing of internal data memory, addressing the internal 256 bytes

 

bdata

 

Internal bit-addressable area, bit-addressable and byte-addressable (16 bytes)

 

xdata

 

External data memory, addressed by mov @dptr

 

pdata

 

Addressing a page (256 bytes) of external data memory, addressed by movx @Rn

 

With the signed and unsigned attributes, you can include the storage type identifier in the variable declaration.

char data var1;

char code text[] = "ENTER PARAMETER:";

unsigned long xdata array[100];

float idata x,y,z;

unsigned int pdata dimension;

unsigned char xdata vector[10][4][4];

char bdata flags;

Note: In previous versions

data char x;

Equivalent to

char data x;

However, in future versions of the Cx51 compiler, this feature will no longer be supported.

Implicit Memory TypesDefault memory type

If the variable default memory type identifier is specified when the variable is declared, the default memory type is automatically selected. Function parameters or automatic variables that cannot be placed in registers are also stored in the default memory area.

The default memory type is determined by the compiler based on the SMALL, COMPACT, and LARGE settings.

Keywords:C51 Reference address:C51 Compiler - Language Extension (1) - Memory Model and Storage Types

Previous article:C51 Compiler - Language Extensions (2) - Data Types
Next article:2-way DS18B20 control

Recommended ReadingLatest update time:2024-11-16 12:24

C51 program for single chip microcomputer to drive standard PC keyboard
C51 program for single chip microcomputer to drive standard PC keyboard   //#i nclude "reg51.h" #i nclude "intrins.h" #i nclude "ku.h" //Key passcode and ascii comparison table sbit sda= p1^0; //Keyboard data line unsigned char dat=0,dat1=0,dat2=0; //Receive keyboard data variable? Store passcode variable to acc
[Microcontroller]
Expert summary! Three pieces of C51 programming experience
 Three Experiences of C51 Programming In the development and application of single-chip microcomputers, high-level languages ​​have gradually been introduced, and C language is one of them. People who are used to assembly language always feel that high-level languages ​​are not as controllable as assembly language.
[Microcontroller]
Proteus C51 simulation learning board 7——LCD1602
LCD1602 is the most basic character LCD display, which can display 16x02=32 characters. So the operation of timing - reading and writing is the most important content. Today, I will take you to read the timing. Before looking at the timing diagram, you need to understand the pin functions of the LCD to better unders
[Microcontroller]
Proteus C51 simulation learning board 7——LCD1602
[C51 self-study notes] Serial communication + RS-232C interface + RS-422A/RS-485 interface
Introduction: Computer communication refers to the information exchange between a computer and an external device or between two computers. There are two modes of communication: parallel communication and serial communication. In multi-microcomputer systems and modern measurement and control systems, serial communic
[Microcontroller]
[C51 self-study notes] Serial communication + RS-232C interface + RS-422A/RS-485 interface
C51 MCU LED Example Program Set
1、 The program implements the function: Let 8 LEDs light up in a row 1—》...——》8 1《——...《——8 The arrows represent the direction of the LED flow, first from 1-8 and then from 8 to 1. The program has been tested and runs normally // If you use this code to test, pay attention to which port your LED is connected to the mi
[Microcontroller]
C51 Programming 11-Interrupts (Interrupt Principles 1)
In the previous IO chapter, the matrix keyboard and LED were used. The main function used their functions to detect whether the matrix keyboard was pressed and whether the LED needed to be lit. As shown in the following code, the keyboard scan and display are continuously executed in the loop. /*********************
[Microcontroller]
C51 Programming 11-Interrupts (Interrupt Principles 1)
Use of C51 header file INTRINS.H
The INTRINS.H function will make it as easy for you to use as in assembler. Internal function description _crol_ Characters rotate left _cror_ Characters rotate right _irol_ Integer circular left shift _iror_ Integer rotate right _lrol_ Circular left shift of long integer _lror_ long integer circular right
[Microcontroller]
24C01 read and write c51 source code sharing
   Many NOPs in the program are redundant. I hope readers can further streamline them, but they must be verified.   Atmel 24C01 is special and simple.   51 crystal oscillator is 11.0592MHz   -----------------------------------------------------------------------------*/   #include “reg51.h   #include ”intrins.h“   s
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号