18F2525 Stack Pointer


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2005
    Location
    Dayton, Ohio
    Posts
    72

    Default 18F2525 Stack Pointer

    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?
    Jim Robertson
    "MilesTag" DIY Lasertag
    www.lasertagparts.com/mtdesign.htm
    Dayton, Ohio

  2. #2
    Join Date
    Jan 2005
    Location
    Australia
    Posts
    20


    Did you find this post helpful? Yes | No

    Default

    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.
    Yuantu Huang

  3. #3
    Join Date
    Sep 2005
    Location
    Dayton, Ohio
    Posts
    72


    Did you find this post helpful? Yes | No

    Default

    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
    Jim Robertson
    "MilesTag" DIY Lasertag
    www.lasertagparts.com/mtdesign.htm
    Dayton, Ohio

Similar Threads

  1. PBP method to POP or PUSH to 18F2525 stack?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 26th September 2009, 20:09
  2. Software Stack
    By yasser hassani in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th December 2007, 10:04
  3. Why is my PIC18F452 reseting?
    By Vincent in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 7th June 2006, 23:35
  4. Stack Under flow
    By Wayne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 14th September 2005, 13:22
  5. 48 level Software Stack
    By Darrel Taylor in forum Code Examples
    Replies: 0
    Last Post: - 30th November 2003, 01:07

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts