Oxygen Basic

Programming => Problems & Solutions => Topic started by: Brian Alvarez on January 02, 2019, 11:22:38 PM

Title: How to GOSUB to an address?
Post by: Brian Alvarez 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)
Title: Re: How to GOSUB to an address?
Post by: Brian Alvarez on January 03, 2019, 12:02:08 AM
This is how i am doing it right now. Image attached.

Title: Re: How to GOSUB to an address?
Post by: Charles Pegge 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.
Title: Re: How to GOSUB to an address?
Post by: Brian Alvarez on January 03, 2019, 03:03:53 AM
Thanks charles, i didnt know that. This is much cleaner.