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

reentrant

i am using an 89v51rd2 controller with out external RAM, i use the following reentrant function for one of the functionalities, i cant avoid it because this function can be recursively called any no of times,

void reentrantfunction(unsigned char data1, unsigned char data2) compact reentrant
{ unsigned char local1, local2 = 0;

if(data2) statements;

switch(data2) { case 0: ……. break; ………… case 5: ….. break; } Function2();

for(local1=0; (local1<25); local1++) { Function3();

if(global1) { Global2[local2] = local1; local2++; } Global3 = xx; Function4(); } If (Local2) { Global4 +=1;

for(data2=0;data2<local2;data2++) { Rentrantfuncion (global2 [data2],global4); } Global4 -=1; }
}

this is how my startup file stack initialization looks like..

IBPSTACK EQU 0
IBPSTACKTOP EQU 0FFH+1

XBPSTACK EQU 0
XBPSTACKTOP EQU 0FFFFH+1

PBPSTACK EQU 1
PBPSTACKTOP EQU 02FFH+1

i am having problems with this function, the speed for now is not a concern but the functionality itself goes wrong somewhere.. does the code ring bells to anyone ??

Parents
  • I guess I have, the code is for you to see.

    The code shows the body of the function. It does not show any function declarations.

    I am not sure of the linker configuration, could you help me on that ??

    The linker configuration only needs to be modified if your device supports several pages of pdata, instead of just one (the default for a '51).

    http://www.keil.com/support/docs/1848.htm

    PBPSTACK EQU 1
    PBPSTACKTOP EQU 02FFH+1
    

    Where did the 02FFH + 1 for the top of the stack come from - was that a default value or did you intentionally set it to 0x300 ? pdata is usually the first 256 bytes of xdata memory, and trying to set the top of the stack of 0300h might mess things up a bit.

    yes, there is enought space on the stack, because i havent used a lot of local variables.

    Is there also enough room for the stack to grow ? Judging from value for PBPSTACKTOP, the stack may not be located in memory where you think it is, and overwrite other variables in xdata.

    Then again, Andys suggestion is probably worth investigating. Why not turn the recursive algorithm into an iterative one and skip all the messy reentrant stuff ?

Reply
  • I guess I have, the code is for you to see.

    The code shows the body of the function. It does not show any function declarations.

    I am not sure of the linker configuration, could you help me on that ??

    The linker configuration only needs to be modified if your device supports several pages of pdata, instead of just one (the default for a '51).

    http://www.keil.com/support/docs/1848.htm

    PBPSTACK EQU 1
    PBPSTACKTOP EQU 02FFH+1
    

    Where did the 02FFH + 1 for the top of the stack come from - was that a default value or did you intentionally set it to 0x300 ? pdata is usually the first 256 bytes of xdata memory, and trying to set the top of the stack of 0300h might mess things up a bit.

    yes, there is enought space on the stack, because i havent used a lot of local variables.

    Is there also enough room for the stack to grow ? Judging from value for PBPSTACKTOP, the stack may not be located in memory where you think it is, and overwrite other variables in xdata.

    Then again, Andys suggestion is probably worth investigating. Why not turn the recursive algorithm into an iterative one and skip all the messy reentrant stuff ?

Children