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

can same memory space use two diff variables ?

Dear Sir,

I m in beginning phase of 8051 with C. i have compiled my c file and i found in .m51 file that one of the SFR and a user defined variable share the same memory space(0080H) .How it's possible.Could you pls explain me.
.M51 lists ....

------- MODULE func1

D:0080H PUBLIC PORT0
I:0080H PUBLIC variabl1

Kindly help with reference to above.

regards,
Arup

  • Although they might look as if they're in the same location, they are not.

    Each one is in a different 'address space' and just happen to have the same offset.

    I suggest you look at the bible for details:

    Chapter 1 - 80C51 Family Architecture:
    www.nxp.com/.../80C51_FAM_ARCH_1.pdf

    Chapter 2 - 80C51 Family Programmer's Guide and Instruction Set:
    www.nxp.com/.../80C51_FAM_PROG_GUIDE_1.pdf

    Chapter 3 - 80C51 Family Hardware Description:
    www.nxp.com/.../80C51_FAM_HARDWARE_1.pdf

  • How it's possible.Could you pls explain me.

    If you want the long, detailed explanation, you will need to refer to document describing the 8051 architecture, especially the memory architecture:

    Chapter 1 - 80C51 Family Architecture:
    www.nxp.com/.../80C51_FAM_ARCH_1.pdf

    The short explanation is that the variables simply do not share the same memory space. Let's look at the listing file again:

    D:0080H PUBLIC PORT0
    I:0080H PUBLIC variabl1
    

    Do you see the memory type specifier ("D:", "I:") in front of the address ? It indicates that the first variable is in directly addressable data memory, and the second variable is in indirectly addressable data memory. The 8051 uses different instructions to access data in directly and indirectly addressable memory, and above address 0x7F this distinction will actually access different memory areas (direct accesses will access the Special Function Registers, while indirect accesses will access internal RAM if available). An instruction that accesses data memory directly at address 0x80 will actually access PORT0, while an instruction that indirectly accesses data memory at address 0x80 will access the byte of internal RAM at this address.

    Read the document linked above for the detailed explanation.

  • Yes, it is possible for two variables to have the same address - even in the same Address Space!

    This is a result of the Overlaying scheme used by the Keil C51 compiler for Automatic variables (ie, non-static local variables).

    But that's not what you're seeing here.

  • I understood. Thanks to everybody for the quick help.

    regards

    Arup

  • dear sir,
    what i understand is above 007F in internal data memory if my SFR occupies x no of bytes of memory ,then same memory location(numerical) i can use for user defined variables in different addr space i.e IDATA

    correct me if wrong.

    thanks,
    Arup

  • what i understand is above 007F in internal data memory if my SFR occupies x no of bytes of memory ,then same memory location(numerical) i can use for user defined variables in different addr space i.e IDATA

    DO read 'the bible'

    while your statement abobe is basically correct there is no such thing as my SFR and no SFR "occupies x no of bytes", they all 'occupy' ONE.

    I do appreciate, that your expressions may be due to 'language', but if you had (as you MUST) studied 'the bible' I am sure that the language woul have been clearer.

    Erik

  • what i understand is above 007F in internal data memory if my SFR occupies x no of bytes of memory ,then same memory location(numerical) i can use for user defined variables in different addr space i.e IDATA<p>

    The SFR area contains 128 bytes. What SFRs these 128 bytes contain, and at which address, mostly depends on the type of chip you are using. The chip documentation will provide this information.

    Whether your chip also has 128 of (indirectly addressable) RAM starting at address 0x80 also depends on what chip you are working with. Information about this will also be in the chips documentation.

    If your chip has the 128 bytes of RAM at address 0x80, then they will be usable as part of the IDATA space.

    (IDATA refers to all internal RAM that is indirectly addressable, which means that it ranges from 0x00 to 0xFF. Be aware that the low addresses also contain the register space and the bit-adressable area.

    DATA refers to directly addressable internal RAM, which means 0x00 to 0x7F).

  • "there is no such thing as my SFR"

    True for a standard chip, but (possibly) not if you're using a softcore, or something like the old Triscend...

  • " no SFR 'occupies x no of bytes', they all 'occupy' ONE."

    The so-called "bible" refers to the (TH0+TL0) and (TH1+TL1) pairs as "16-bit registers"

    DPTR is also a 16-bit register (thought also accessible as DPH and DPL)

    There maybe others specific to particular derivatives?