Keil Logo

XBANKING.A51

This file provides routines for far (HDATA) and far const (HCONST) memory type support. The extended LX51 linker/locator manages the extended address spaces HDATA and HCONST that are addressed with far and far const. The Cx51 Compiler uses a 3-byte generic pointer to access these memory areas.

Variables defined with the far memory type are placed in the memory class HDATA. Variables defined with const far get the memory class HCONST. The LX51 linker/locator allows you to locate these memory classes in the physical 16MB code or 16MB xdata spaces. To use far memory with the C51 Compiler for classic 8051 devices you must use the VARBANKING directive.

The memory types far and far const provide support for the large code/xdata spaces of new 8051 devices. If the MCU you are using provides an extended 24-bit DPTR register, you may adapt the default version of the file XBANKING.A51 and define the symbols listed in the following table.

Name Description
?C?XPAGE1SFR SFR address of DPTR page register that contains DPTR bit 16-23.
?C?XPAGE1RST Reset value of the ?C?XPAGE1SFR to address the X:0 region. This setting used by the C51 compiler when you are using the VARBANKING(1) directive. With VARBANKING(1), the C51 compiler saves the ?C?XPAGE1SFR at the beginning of interrupt functions and sets this register to the ?C?XPAGE1RST value

The far memory type allows you to address special memory areas like EEPROM space or strings in code banking ROM. Your application accesses these memory areas as if they are a part of the standard 8051 memory space. Example programs in the folder C51\EXAMPLES\FARMEMORY show how to use the C51 far memory type on classic 8051 devices. If an example that fulfills your requirements is not provided, you may adapt the access routines listed in the table below.

Access Routine Description
?C?CLDXPTR, ?C?CSTXPTR load/store a BYTE (char) in extended memory.
?C?ILDXPTR, ?C?ISTXPTR load/store a WORD (int) in extended memory.
?C?PLDXPTR, ?C?PSTXPTR load/store a 3-BYTE pointer in extended memory.
?C?LLDXPTR, ?C?LSTXPTR load/store a DWORD (long) in extended memory.

Each access routine gets as a parameter the memory address in a 3-byte pointer representation in the MCU registers R1/R2/R3. The register R3 holds the memory type value. For classic 8051 devices, the Cx51 Compiler uses the following memory type values:

R3 Value Memory Type Memory Class Address Range
0x00 data / idata DATA / IDATA I:0x00-I:0xFF
0x01 xdata XDATA X:0x0000-X:0xFFFF
0x02-0x7F far HDATA X:0x010000-X:0x7E0000
0x80 unused
0x81-0xFD far const HCONST C:0x800000-C:0xFC0000 (far const is mapped into the banked memory areas)
0xFE pdata XDATA one 256-byte page in XDATA memory
0xFF code CODE / CONST C:0x0000-C:0xFFFF

The R3 values 0x00, 0x01, 0xFE and 0xFF are already handled within the run-time library. Only the values 0x02 - 0xFE are passed to the XPTR access routines described above. The AX51 macro assembler provides the MBYTE operator that calculates the R3 value that needs to be passed to the XPTR access function. Below is an AX51 Assembler example for using XPTR access functions:

MOV  R1,#LOW   (variable)   ; gives LSB address byte of variable
MOV  R2,#HIGH  (variable)   ; gives MSB address byte of variable
MOV  R3,#MBYTE (variable)   ; gives memory type byte of variable
CALL ?C?CLDXPTR             ; load BYTE variable into A
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.