Welcome, Guest. Please login or register.

Author Topic: Stack related program crash  (Read 1989 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline peroxidechickenTopic starter

  • Full Member
  • ***
  • Join Date: Apr 2002
  • Posts: 170
    • Show all replies
Stack related program crash
« on: June 18, 2004, 09:21:00 PM »
I'm writing a program that stores all of it's variables and some other data starting at the low end (closer to address 0) of stack space and continuing for what I believe to be less than 1000 bytes.  First, the initialization code checks the task structure to make sure the normal 4KB or more is there, then clears the desired space before using it.  This was fine until I added a few more variables recently and started to experience crashes after the terminating rts instruction.  I remedied this by tidying up/getting rid of the few variables the program no longer uses.  But this program is far from done and soon enough, I'm going to need extra variables again.  

I took this approach to variable storage thinking that all the stack space lower than the current stack pointer is up for grabs - can anyone set me straight?  
H2O2
 

Offline peroxidechickenTopic starter

  • Full Member
  • ***
  • Join Date: Apr 2002
  • Posts: 170
    • Show all replies
Re: Stack related program crash
« Reply #1 on: June 20, 2004, 01:56:28 AM »
Thanks Piru - I can see now that I wasn't being system friendly in the way I stored my variables.  

But I'm sure I didn't exceed the low end of stack space and I also didn't overwrite the stack pointer.  I understand how my variables might become corrupted, what I don't understand is how the operating system lost any data it needed to terminate my task.  
H2O2
 

Offline peroxidechickenTopic starter

  • Full Member
  • ***
  • Join Date: Apr 2002
  • Posts: 170
    • Show all replies
Re: Stack related program crash
« Reply #2 on: June 22, 2004, 01:36:20 AM »
Hi there PiR.  I tried that and that address wasn't being changed/overwritten.  I didn't bother to see if the memory area pointed to by that address was being changed - I know this sounds like famous last words, but there's no way my program would be modifying memory like that.  

Anyway, I went and did what Piru suggested - not only does it work but it made my variable initialization code smaller too!  
H2O2