The MCU I used is SM8958A,which has 1K bytes on-chip RAM, 256 bytes of it are the same as general 8052 internal memory structure while the expanded 768 bytes on-chip RAM can be accessed by external memory addressing method (by instruction MOVX).The SCONF and RCON should be setting when the expanded 768 bytes on-chip RAM is used.The meaning of RCON is below:
SM8958A has 768 byte on-chip RAM which can be accessed by external memory addressing method only. (By instruction MOVX). The address space of instruction MOVX @Rn is determined by bit 1 and bit 0 (RAMS1, RAMS0) of RCON. The default setting of RAMS1, RAMS0 bits is 00 (page0).
RAMS1 RAMS0 MOVX @Ri i=0,1 mapping to expended RAM address 0 0 $0000 ~ $00FF 0 1 $0100 ~ $01FF 1 0 $0200 ~ $02FF
Now I write the code below:
unsigned long pdata a; unsigned long xdata b; SCONF |= 0x02; //enable the 768 Ram RCON |= 0x01; //$0100 ~ $01FF
When I press F5, I find the position of 'a' in the memory is X:0x0001A4,and the auto disassemble instruction is mov r0, #0xA4, however,the position of 'b' in the memory is X:0x0002BF,and the auto disassemble instruction is movx DPTR,#02BF.
Finally, the program where used 'a' runs wrong,but the program where used 'b' runs right.
But when I program the HEX file into the MCU, let it run in the hardware , the program runs ok.
So, I'm very puzzled: Keil's Debug is right or wrong?
Note This message was edited to reduce width.
I am puzzled that while the address of 'a' in memory is X:0x0001A4, the disassemble instruction is mov R0,#0xA4, not mov DPTR,#0x01A4
What part of "there's absolutely nothing wrong with that" didn't you get the first time? If PDATA behaved exactly like XDATA to work, why would they exist as separate memory classes in the first place?
Frankly, you need to spend a lot more time on studying the 8051 architecture (memory architecture, opcodes, addressing modes, and all that) before going ahead reading disassembled code and drawing conclusions from what you think you see.
Thank you for helping me. Now I understand more than before. I config Pdata in the Startup.A51 file.
In simulation, P2 is the uppermost address of pdata variable, but in real mcu, P2 is no effect . So I guess keil's simulation have some flaw.