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

Does C51 support Extend Stack(stack located in external memory)

I'v got a 8051 that has a extend stack pointer in sfrs(named ESP), and the stack can be located in extern memory(xdata). The new ESP sfr has 4bits, so with the old sp this 8051 gets a 12bit stack pointer.The push,pop,lcall,acall instructions affect the stack pointer implicitly. But it seems that the C51(or Cx51)compiler does'nt support this extend stack pointer, the most familiar mode is xdata reentrant mode. I'v investigated the xdata reentrant mode, it uses ?C?CALL_XBPV, ?C?CALL_XBP,?C?RET_XBP, ?C?RET_XBPV,?C?ADDXBP,?C?XBPOFF lib functions to manipulate the ?XBP stack pointer.I try to replcace this lib functions in order to support the extend stack pointer, and find several problems as follows:
1ã€While using the xdata reentrand mode, and specifing the "RET_XSTK" option in C51, the return value in idata stack will be copied to the xdata stack, but not all functions. The leaf functions in call chain do'nt copy return address. The come the problem, if a leaf function has many parameters passed in xdata stack, the xdata will lay out as follow:

|---------------|<-------------low addr, ?XBP
|current func |
| |
|---------------|
| param n|
|---------------|
| ... |
|---------------|
| param 1 |
|---------------|
| |
|---------------|<-------------High addr

but the extend stack's layout is as follows:

|---------------|<-------------low addr
|---------------|
| param 1|
|---------------|
| ... |
|---------------|
| param n|
|---------------|
| return pc |<------additional 2bytes!!
|---------------|
|currentfunc |
|---------------|<-------------High addr, ESP:SP

the param is partitioned by the "return pc" in the stack! If one want to refer to the paramn, an offset of 2byte must be subtracted from ESP:SP. But in xdata reentrant mode, no offset should be added to access the paramn.

2. Sometiemes the C51 compiler access the local vars using ?XBP directly. It moves the ?XBP to dptr, and adds some offset to the dptr, and accesses the local vars using "mov A,@dptr". In these cases, no lib function(such as ?C?XBPOFF) is called, and there is no chance to hack the local var accessing.

The IAR systems seems to support extend stack(such as dallas 400 chip and many other chips). Does any c51
new version support extend stack?

0