Author Topic: How to GOSUB to an address?  (Read 329 times)

0 Members and 1 Guest are viewing this topic.

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 521
    • PluriBASIC
How to GOSUB to an address?
« on: January 02, 2019, 11:22:38 PM »
Hello, Is there a way to do something like this?:

Code: [Select]
GOSUB @ThisLabel

RETURN 0

Thislabel:
  ' do so some stuff....
RETURN

It currently compiles but return just exits the function instead of returning to the GOSUB call. Same goes for regular GOSUB calls:

Code: [Select]
GOSUB ThisLabel

' Never gets here.

RETURN 0

Thislabel:
  ' do so some stuff....
RETURN

 This is how it is documented, but i was wondering whats the difference between GOTO and GOSUB? is there a way to return to the calling statement instead of exiting the module?

 (Im trying to avoid doing my own stack of calls as im doing now)
« Last Edit: January 02, 2019, 11:41:34 PM by Brian Alvarez »

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 521
    • PluriBASIC
Re: How to GOSUB to an address?
« Reply #1 on: January 03, 2019, 12:02:08 AM »
This is how i am doing it right now. Image attached.


Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4222
    • Oxygen Basic
Re: How to GOSUB to an address?
« Reply #2 on: January 03, 2019, 02:12:46 AM »
Hi Brian,

o2 gosubs are bare-metal Asm calls to a label, and should be terminated by ret instead of return.

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 521
    • PluriBASIC
Re: How to GOSUB to an address?
« Reply #3 on: January 03, 2019, 03:03:53 AM »
Thanks charles, i didnt know that. This is much cleaner.
« Last Edit: January 03, 2019, 03:10:37 AM by Brian Alvarez »