Shop OBEX P1 Docs P2 Docs Learn Events
Access to GOSUB return address on BS2E — Parallax Forums

Access to GOSUB return address on BS2E

Martin_HMartin_H Posts: 4,051
edited 2010-04-30 02:48 in BASIC Stamp
In the Basic Stamp 1 W6 held the return address after a GOSUB.· I'm wondering if on the Basic Stamp 2E if there's a way to access the GOSUB return address?· What I would like to do is in my main module call a TaskDispatch

TaskDispatch:
· ' Store GOSUB return address in the Scratchpad
· PUT 0, Word·W6··· ' I know its not W6·on the BS2E
· PUT 2, TaskIndex
· RUN TaskBank

At the head of the main module I would see if there was a return address at 0 in the scratch pad and then load it into the location that holds the GOSUB return address. I would then execute a return so I could resume program execution where· I called TaskDispatch.

· Task = TaskReadLine
· GOSUB TaskDispatch
· ' More stuff after the GOSUB

If there's no way to access the GOSUB return address I have another way to do it using GOTO's and a BRANCH at the head of the module.· It would be much cooler with access to the return address.

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2010-04-30 02:28
    The return index is not available on the Stamp 2, so I think you will have to resign yourself to managing your own BRANCH both forward and back. Both the return stack and the for-next indexes are trashed by the RUN command.

    The Stamp2 uses an indexed stack scheme similar to the BS1. The stack does not hold the actual return address, rather, it holds an index into a table of return addresses that are stored at the top of the eeprom program memory.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Martin_HMartin_H Posts: 4,051
    edited 2010-04-30 02:48
    Thanks. That's what I was afraid of because I couldn't find any information about access to the return stack. That's a shame, but the on branch technique will work.
Sign In or Register to comment.