48 level Software Stack


Closed Thread
Results 1 to 1 of 1
  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959

    Lightbulb 48 level Software Stack

    Tired of only having 4 Levels of Nested Gosub's ??
    Or, maybe you want to write a "Recursive" routine in PicBasic Pro ?? (MPASM required)
    Now you can !!!


    swStack.inc is an include file that will allow you to create up to a 48 level Software Stack on a 14-bit Core PIC.
    On an 18F PIC, the Stack size is only limited by the amount of available memory.

    The include file gives 2 Macro Commands:
        swGosub - Software Gosub
        swReturn - Return from Software Gosub

    The Macro's are used almost exactly like PBP Gosub and Return, but since they are Assembly language the syntax is a little bit different.

    PBP Example of normal Gosub:
    Code:
    Sub1:
         Hserout ["Hello"]
    Return
    
    Gosub Sub1
    swGosub Example:
    Code:
    Sub1:
         Hserout ["Hello"]
    @ swReturn
    
    @ swGosub _Sub1           ; Note the underscore before Sub1
    The Stack size must be set using the Constant "StackSize", prior to including swStack.inc
    It is limited by the largest Word Array that you can fit into 1 bank, which varies, depending on the PIC chip used. With some modifications, that maximum could be increased.

    Status of the Stack can be monitored with these variables that are defined in the swStack.inc file:

    Code:
       StackPTR      Var  Byte    ' Pointer to current Top of Stack
       StackFull     Var  bit     ' if=1, you cannot do another swGosub
       StackEmpty    var  bit     ' if=1, you cannot do a swReturn
       SToverflow    var  bit     ' swGosub called when Stack was Full
       STunderflow   var  bit     ' swReturn called when Stack was Empty

    ** An overflow or underflow does not reset the PIC like a Hardware overflow would. It simply won't execute the Gosub or Return. So you will either need to make sure it never happens, or handle the error in your program. You could also modify the swStack.inc file, and have it reset the PIC on an over/underflow. **

    For an example of how to use swStack.inc, see the Test_swStack.pbp program.

    Thanks again to John Barrat for solving my forward declaration problem.

    Hope this helps your program.

    Darrel Taylor


    P.S. If you like this program, do me a favor and scroll down to the bottom of this page and "Select a rating" for this thread. Thanks!
    Attached Files Attached Files

Similar Threads

  1. Gerber - PCB Layout Software??
    By kevj in forum General
    Replies: 10
    Last Post: - 3rd April 2013, 06:51
  2. Replies: 24
    Last Post: - 1st December 2009, 08:01
  3. Software Stack
    By yasser hassani in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th December 2007, 10:04
  4. PIC16F917 stack issues
    By Jerson in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 20th February 2007, 15:25
  5. Replies: 3
    Last Post: - 26th November 2006, 21:47

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