Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: Hot_Dog on February 25, 2011, 09:16:37 pm

Title: Goto Label using ASM
Post by: Hot_Dog on February 25, 2011, 09:16:37 pm
If I run a Ti-Basic program and there's an asm( line to run an ASM program, how can I tell the asm program to goto a label inside of the Ti-Basic program?  I'm wondering if there's a B_CALL or something to find the label and continue running the program from that location
Title: Re: Goto Label using ASM
Post by: ztrumpet on February 25, 2011, 10:06:35 pm
Oooh, that's a cool idea.  I don't know of a way, but I'm sure there is a way to do this. :D
Title: Re: Goto Label using ASM
Post by: thepenguin77 on February 25, 2011, 10:16:28 pm
I know there is no bcall explicity made for doing this. But with a little bit ptr hacking it's probably doable. (Essentially change a few numbers so the program returns to the new label instead of where it's supposed to.)
Title: Re: Goto Label using ASM
Post by: jnesselr on February 25, 2011, 10:56:42 pm
You would have to change some variables.  Essentially check from the basic_start and basic_end (There's also one for basic_pc or something like that) for your label, and set basic_pc to it.

EDIT: That should work, if it doesn't, don't say I didn't warn you.  btw, I'm warning you now. ;-) Not that I think it'll do anything bad.
Title: Re: Goto Label using ASM
Post by: z80man on February 26, 2011, 12:30:52 am
Sounds like it could be kind of hard to calculate as each instruction has varying size from only one byte to several hundred or even thousand bytes. You could have the subroutine count the number of carriage returns to find where to jump to.
Code: [Select]
:15->A      //number of instructions to jump
:asm(JUMP   //count 15 carriage returns, then change the BASIC pointer to that address. 
:blah       //14 lines of blah
:if B=4     //destination
Title: Re: Goto Label using ASM
Post by: Hot_Dog on February 26, 2011, 01:09:20 am
Actually, I forgot about searching tokens. 

The calculator has three specific variables for Ti-Basic programs running: where the program starts, where it ends and where it is currently running.  I'll just search through the list of tokens in the program from beginning to end.