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

Re: Far memory access

Hi all,
I force PK51 to generate a SRC file which convert following C code to assemble,

C code:
val = FVAR(unsigned char, 0x800000);

assemble code
MOV R3,#081H
MOV R2,#00H
MOV R1,#00H
LCALL ?C?CLDPTR

But I don't understand
(1) why 80H has been changed to 81H ?
(2) What is happened behind
LCALL ?C?CLDPTR

Thanks in advance

Daniel

  • You'll want to read up about the internal encoding used for generic pointers in the manual.

    The library routine ?C?CLDPTR just does the reading of a byte at a given generic pointer for you.

  • Generic pointers are not flat addresses. They're really a tag byte that represents the memory space, followed by a 16-bit address.

    For what I guess are historical reasons, the tag byte value 0 is not xdata, but the internal data memory space. The first 64K block of xdata has tag value 1. Further blocks of external RAM ("far" or "hdata") have increasing tag values. You can, if you like, view this as the 24-bit generic pointer value having a value 0x10000 more than the actual address.

    01 0000 = offset 0 in xdata
    02 0000 = offset 10000H in external memory
    81 0000 = offset 800000 in xdata

    In addition to the manual, see the "theory of operation" section in the comments in the example XBANKING.A51 code in the lib directory.