PDA

View Full Version : 18F2525 Stack Pointer



milestag
- 22nd November 2005, 18:31
Okay, I found a bug in my code caused by (me) calling subroutines (GoSub) and then using a "GoTo" within that subroutine rather than always using the Return. After a certain number of calls to that subroutine, everything went haywire.

Lucky I remembered seeing a post on earlier this forum about NOT doing that with 18FXXX, and was able to find the problem and fix it. ....after a tedious adventure in creating a hand-drawn flowchart to map my code and find the missing Returns.

My QUESTION is.....could I simply insert a "STKPTR = 0" in order to reset the stack and compensate for a few "illegal" GoTos? I would place this at the TOP of my code allowing me to immediately jump back to the "MainLoop" of the program without having to Return from the current subroutine.

This would still be useful in the interest of speed, to not have to back out of a number nested subroutines. I know it's unorthodox...but will it work?

Yuantu Huang
- 22nd November 2005, 22:26
You may insert @POP before goto. Do not force "STKPTR = 0" and let PIC control STKPTR. Please let me know whether @POP can fix the problem.

milestag
- 23rd November 2005, 13:40
Okay, that makes sense. I am still learning some of the 18FXXX's unique instructions.

Right now the program runs perfectly (since I fixed those Returns). My question was more for some future ideas.

Thanks!!

-Jim