Hi I had many c files in my project. Two of them are main.c and Print.c. I wrote a function delay() in Print.c. I call this function from main.c. After complete execution of delay() code didnot return to main.c. Rather it goes in middle of a function in Print.c. Any body have the solution of my this problem. Regards Farhan Arshad
Your function delay() quite obviously is buggy, then. It's impossible to be more specific given the small amount of facts you presented.
Did you check for stack Overflow?
"Did you check for stack Overflow?" Or for an invalid/uninitialised pointer that could be trashing the stack...?
hi Stack is not over flow. I check the assembly code generated actually in main file when it calls the dalay function the address of next line is 0x0018. When it returns from the delay function it jumps on the 0x0018 of the file which contain the delay function. Here is my delay function.
void delay(int j) { int i; for(i=0;i<j;i++) { } }
Sounds like a stack problem (is the stack pointer correctly initialized). Can you duplicate the problem also in real chip. What is at the end of your 'main' routine? Is there a while (1) loop in main?
hi My main routine ends with a while(1) loop.And SP is initalized with 0x81 in REG51.h Regards Farhan Arshad
My main routine ends with a while(1) loop.And SP is initalized with 0x81 in REG51.h No, it is not, is is defined as 0x81 Erik
"SP is initalized with 0x81 in REG51.h" You mean this line in reg51.h:
sfr SP = 0x81;
HI I call a function in the main.In that function i call delay(). So there is only one function call before delay is called.(so only after ane function call the stack over flow ??????).Another thing is that when is saw the assembly code generated during debuging it shows that correct address is stored in the stack. But when the function returns it return at the correct address but in the incorrect file. Regards Farhan Arshad
But when the function returns it return at the correct address but in the incorrect file. That would suggest you're just over-interpreting the debugger's behaviour as you're stepping through highly optimized code. In the case at hand, common code folding would mean that identical code found in several places will only exist once, which of code makes it hard for the debugger to tell which source code line this code actually came from...
"so only after ane function call the stack over flow ??????" As I said before, even if the stack doesn't overflow, there are plenty of other opportunities to mess it up! Invalid and/or uninitialised pointers are excellent for trashing memory - including the stack...!