This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

XBANKING, LX51, Pointers and Assembler

Hi! I'm using XBANKING.a51 from
 "Keil\C51\Examples\FarMemory\3 XData Areas on T89C51RD2"
 for access to various types of memory MCU Atmel AT89C5131.

  I'm define memory model - Large, "User Classes" as:

XDATA (X:0x008000-X:0x009FFE)             // off-chip XRAM
HDATA_EEPROM (X:0x020000-X:0x0207FF)      // on-chip EEPROM
HDATA (X:0x010000-X:0x0103FF)             // on-chip XRAM

  And variables as:
in file MAIN.c

unsigned char       *Pointer1, *Pointer2;
unsigned char far   onBufer;              // on-chip XRAM
unsigned char xdata offBufer;             // off-chip XRAM
unsigned code       cBufer = "Welcome";   // on-chip ROM

in file EEPROM.c

#pragma USERCLASS (HDATA = EEPROM)
unsigned char far   EEBufer;              // on-chip EEPROM

I'm programming next code:

Pointer1 = onBufer;                       // pointer to 0x01AABB
Pointer2 = cBuffer;                       // pointer to 0xFFCCDD
memcpy(Pointer1, Pointer2, 20);

Compiling my program and view "Disassembly Window":

...
Pointer1 = onBuffer;
908010   MOV      DPTR,#Pointer1(0x8010)
7402     MOV      A,#0x02                 // on-chip EEPROM area !!!
F0       MOVX     @DPTR,A
A3       INC      DPTR
74AA     MOV      A,#0xAA
F0       MOVX     @DPTR,A
A3       INC      DPTR
74BB     MOV      A,#0xBB
F0       MOVX     @DPTR,A
Pointer2 = cBuffer;
A3       INC      DPTR
74FF     MOV      A,#0xFF
F0       MOVX     @DPTR,A
A3       INC      DPTR
74CC     MOV      A,#0xCC
F0       MOVX     @DPTR,A
A3       INC      DPTR
74DD     MOV      A,#0xDD
F0       MOVX     @DPTR,A
memcpy(Pointer1, Pointer2, 20);
...

Where the bug or my error?

Parents Reply Children
  • OK, I have understood, it turns out, that memory and indexes are allocated as follows:

    +----------------+--------------+------------------------+--------------+-----------+
    |  Memory Type   | Memory Class |  Define in C language  | Address in C | R3 in ASM |
    +----------------+--------------+------------------------+--------------+-----------+
    | on-chip XDATA  |    HDATA     |         far            |  X:0x010000  |   0x02    |
    | off-chip XDATA |    XDATA     |         xdata          |  X:0x000000  |   0x01    |
    |    CODE        |    CODE      |         code           |  X:0x0000    |   0xFF    |
    |    EEPROM      | HDATA_EEPROM | far & (HDATA = EEPROM) |  C:0x0000    |   0x03    |
    +----------------+--------------+------------------------+--------------+-----------+
    * using standard files XBANKING.a51 and EEPROM.c
    


    There is another problem. In the menu "Options for Target" I choose "Memory Model = Lage: variables in XDATA". I have function in my program char Test (char value1, char *value2, char value3) in which parameters transferred through XDATA memory, but not through registers.
    XDATA memory is an off-chip. How to transfer parameters through on-chip XRAM?

  • There is no particular reason why on-chip XDATA has to be HDATA, while off-chip is XDATA.

    Presumably, you are looking at some specific case where this happened to be (or seem) convenient to whoever set it up?

  • I shall ask on another. I define variables as:

     char xdata A; // locate in off-chip XDATA
     char far B;   // locate in on-chip XDATA
    


    If the model of memory LARGE and a variable is defined as char C; , then where is placed a variable? It is necessary for me that in on-chip XDATA.

  • "It is necessary for me that in on-chip XDATA."

    If it is necessary, then just specify it explicitly.
    Simple.