Keil Logo

far

The far memory type may be used for variables and constants. This memory is accessed using 24-bit addresses and may be on-chip or external.

  • For variables, far memory is limited to 16M. Objects are limited to 64K and may not cross a 64K boundary. Variables declared far are located in the HDATA memory class.
  • For constants (ROM variables), far memory is limited to 16M. Objects are limited to 64K and may not cross a 64K boundary. Constant variables declared far are located in the HCONST group.

Declare far objects as follows:

unsigned char far far_variable;

unsigned char const far far_const_variable;

The actual address range that can be addressed with the far memory type depends on the chip architecture or the banking configuration file. The far memory is addressed using 3-byte generic pointers. The mapping of the Memory Type Byte (uppermost byte) differs for each architecture and is shown below:

  • NXP 80C51MX: the complete 16MB address space can be addressed without restrictions.

    Memory Type Byte Addressed Memory Region
    0x00 XDATA, HDATA (0x000000 - 0x00FFFF)
    0x01 - 0x7E HDATA (0x010000 - 0x7EFFFF)
    0x7F DATA, IDATA, EDATA (0x7F0000 - 0x7FFFFF)
    0x80 CODE, ECODE (0x800000 - C:0x80FFFF)
    0x81 - 0xFF ECODE (0x810000 - C:0xFFFFFF)
  • Dallas Contiguous Mode: far and const far are limited to 8MB-64KB address space.

    Memory Type Byte Addressed Memory Region
    0x00 DATA/IDATA/BDATA
    0x01 - 0x7F XDATA Memory (X:0 - X:0x7EFFFF)
    0x80 Unused
    0x81 - 0xFF CODE Memory (C:0 - C:0x7EFFFF)
  • XBANKING.A51 Configuration File: far and const far are handled by user provided routines. The following table lists the default mapping of the file ..\C51\LIB\XBANKING.A51.

    The examples in the folder ..\C51\Examples\FarMemory (i.e. for ADuC812) may have a different mapping. The actual mapping is described in each XBANKING.A51 file.

    Memory Type Byte Addressed Memory Region
    0x00 DATA/IDATA/BDATA
    0x01 classic 8051 XDATA Memory (X:0 - X:0xFFFF)
    0x02 - 0x7F extended HDATA Memory (X:0x10000 - X:0x7EFFFF)
    0x80 Unused
    0x81 - 0xFD extended HCONST Memory (C:0x800000 - C:0xFC0000).
    0xFE PDATA Memory (one 256-byte page in XDATA)
    0xFF classic 8051 CODE Memory (C:0 - C:0xFFFF)
  • L51_BANK.A51 Configuration File: far and const far can be handled with code banking routines.

    Memory Type Byte Addressed Memory Region
    0x00 DATA/IDATA/BDATA
    0x01 classic 8051 XDATA Memory (X:0 - X:0xFFFF)
    0x02 - 0x40 extended HDATA Memory (X:0x10000 - X:0x3FFFFF)
    0x41 - 0x80 Unused
    0x81 - 0xC1 extended HCONST Memory mapped to code banks (B0:0x0 - B31:0xFFFF).
    0xC2 - 0xFD Unused
    0xFE PDATA Memory (one 256-byte page in XDATA)
    0xFF classic 8051 CODE Memory (C:0 - C:0xFFFF)

     

Note

  • Pointer arithmetic for far objects is performed using 16-bit math operations by default. The upper byte of the complete 24-bit address is unchanged even if the operation's result is larger than 0xFFFF. You may coerce the compiler to use 24-bit math by using long types or casting constants to long types in pointer manipulations. For example:
    char far *fp;
    unsigned long i;
    unsigned long ttl;
    
    for (ttl=0, i=0; i<0x20000; i++)
      {
      ttl += fp[i];
      }
    
  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.