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 ??
Jasche K, Just don't use recurrence. It is asking for truble!
unsigned char local1, local2 = 0,j;
Are you sure you want this statement? It's syntactically legal, but ut does not initialize local1 to 0 and local2 to j. Local1 is uninitialized and local2 is initialized to the results of the comma operator, which in this case is j. Evaluating "0" is a waste of time. You probably want
unsigned char local1 = 0; unsigned char local2 = j;
As a matter of style, I recommend declaring each variable individually even if you're going to leave them uninitialized.
This function takes two parameters, each one byte. Per the C51 calling conventions, these parameters will be passed in registers. You'll need stack space for locals and temporaries. Return addresses always go on the hardware stack, so also be sure your SP points to a valid space with enough room to hold the expected depth of recursion.
thanks all, i guess the solution is to write without recursion, i will try that and get back to the post.
this forum is awesome, i am havin numerous answers in 24 hours.
thanks guys