Author Topic: Lbl-Goto vs If:Then...Else Question  (Read 3345 times)

0 Members and 1 Guest are viewing this topic.

Demon

  • Guest
Lbl-Goto vs If:Then...Else Question
« on: January 02, 2007, 04:26:00 pm »
In version 3 of PyroEdit I'm making, I wanted to put as much into the PyroEdit program  (prgmAPYROEDT) as possible so a user doesn't have to have all those darn subroutines taking up Archive space on the calc.  I put all the functions that execute when a user preses a key in the main program but I don't know what the best and fastest way of checking would be.

It used to be:
c1-->
CODE
ec1...
Repeat Ans
...
getkey->K
End
...
prgmPSEK
...
Endc2
ec2
Where prgmPSEK figures does the corresponding function according to what key was pressed and returns back to the main program immediatly after that function was executed (or if the function did a "break" and forced a Return).
c1
-->
CODE
ec1If Ans=11:Then

Return:Endc2
ec2


Now it does this in the main program:
c1
-->
CODE
ec1...
Repeat Ans
...
getkey->K
End
...
If Ans=11:Goto 11
If Ans=12:Goto 12
If Ans=12:Goto 13
...

Lbl A
End
...
Lbl 11
...
Goto A
Lbl 12
...
Goto A
Lbl 13
...
Goto A
...c2
ec2


I thought about doing this:
c1
-->
CODE
ec1...
Repeat Ans
...
getkey->K
End
...
If Ans=11:Then
...
End
If Ans=12:Then
...
End
If Ans=12:Then
...
End
End
...
c2
ec2
and so on, but the functions range from a few bytes to over a kilobyte, and I'm thinking that if I do it this way, it would be really slow 'cause TIOS would have to scan over kilobytes worth of code until an If statement has a condition that matches and run the corresponding code, and it'd have to do this every time the user presses a key.
With the Lbl-Goto method, TI-OS would only have to look at a few bytes of code every time the user presses a key and then jump to the corresponding function (if one exists) and then jump back to Lbl A to close out the "End"s it left open, and it could do this faster than having to scan over all that code every time.
But I'm not sure.

What should I do?

graywolf

  • Guest
Lbl-Goto vs If:Then...Else Question
« Reply #1 on: January 02, 2007, 05:23:00 pm »
I think that Lbl-Goto method should work better, but this is only based on 89 experience. I dunno about 83/84.

Offline tifreak

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2708
  • Rating: +82/-3
  • My Kung Fu IS strong...
    • View Profile
    • TI-Freakware
Lbl-Goto vs If:Then...Else Question
« Reply #2 on: January 03, 2007, 04:39:00 am »
I dont know what my opinion is worth on this matter, but here is what I am doing:

Using While loops, you can create the same effects of a Lbl-Goto system. Basically, you need a main while loop, which will encompass everything. Then manipulating the value of the variable for the While loop, you can move around the program very quickly. Here is an example:

c1-->
CODE
ec1
While W=1
Projects: AOD Series: 75% | FFME: 80% | Pokemon: 18% | RPGSK: 60% | Star Trek: 70% | Star Trek 83+: 40% | TI-City: 5%

Offline dinhotheone

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 410
  • Rating: +2/-1
    • View Profile
Lbl-Goto vs If:Then...Else Question
« Reply #3 on: January 03, 2007, 09:13:00 am »
just remember that lbl/goto have to start jumping at the start of the program where if-then's skip straight from the if-then. it seems like it would depend how much stuff you have before the subroutines. if you have alot then i'd use if-then otherwise i'd use lblgoto. If you are unsure what "alot" is you can just force lbl-goto be the best by rewriting your code so that the subs are up top.

Demon

  • Guest
Lbl-Goto vs If:Then...Else Question
« Reply #4 on: January 03, 2007, 09:50:00 am »
What if I put it back in the subroutine and do this:
c1-->
CODE
ec1If :
Then

End
If :Returnc2
ec2

Is this optimal enough or is there an even better way?  I need the fastest way possible 'cause this thing is huge!

Offline Speler

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 857
  • Rating: +6/-2
    • View Profile
Lbl-Goto vs If:Then...Else Question
« Reply #5 on: January 03, 2007, 09:56:00 am »
Start off the program with a goto 0 representing the begining of the code and then follow with the subroutines begining each subroutine with lbl and ending them with end.  Start a while loop after lbl 0 with the code you run in it.  Inside the while loop goto the subroutines.

Demon

  • Guest
Lbl-Goto vs If:Then...Else Question
« Reply #6 on: January 03, 2007, 10:04:00 am »
So do:
c1-->
CODE
ec1
Goto 0
Lbl 2
Repeat K=22
Repeat Ans
getkey
End
If Ans=11:Goto 11
If Ans=12:Goto 12
...
Lbl 1
End

Lbl 11
Do this
Goto 1
Lbl 12
Do this
Goto 1
...
Lbl 0
Start up the program
Goto 2
c2
ec2

How well do you think this will work?

Offline Speler

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 857
  • Rating: +6/-2
    • View Profile
Lbl-Goto vs If:Then...Else Question
« Reply #7 on: January 03, 2007, 10:09:00 am »
No not what I meant...

Ok here's example code:

goto 0
lbl a
code
end
lbl b
code
end
etc.
lbl 0
while condition
if *** goto a
if *** goto b
if *** goto c
code
end

Demon

  • Guest
Lbl-Goto vs If:Then...Else Question
« Reply #8 on: January 03, 2007, 10:15:00 am »
I know, but PyroEdit's loader is not exactly small either, so I put 0 where PyroEdit will boot up, and then jump to 2 where it will wait for the user to click something and keep jumping back to inside the loop after and if a function was executed to close out the End that was left open.  That way there will only be less than a hundred bytes of code before the subroutines (which isn't much), and it dosen't have to read over the thousand-and-something byte loader looking for the matching Lbl.

Offline dinhotheone

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 410
  • Rating: +2/-1
    • View Profile
Lbl-Goto vs If:Then...Else Question
« Reply #9 on: January 03, 2007, 02:26:00 pm »
it seems to me like you are worried it will take a long time to jump over your subs at the start of the program, the only time lbl-goto have a speed issue is if you are repeatedly doing it in a loop while looking for something really far away. Splelers method combines the strengths of both skipping structures and jumping structures so his way is defenitely the fastest(while in the program). That, correct me if im wrong, is better than having a half second or even a second shorter start up time. also you mention jumping over the 1000.. byte loader? the only time this would be a concern would be if you had a lbl after this loader but if you include all the subs before the loader it shoodnt be a problem, splelers method uses while loops to get past the loader, this is optimal because the start of the while is random access, so the calc will immediately go to it when you hit the end, as opposed to sequential access like in lbl-goto where it has to look over everything to find the lbl. I hope i answered everything...

Demon

  • Guest
Lbl-Goto vs If:Then...Else Question
« Reply #10 on: January 03, 2007, 02:31:00 pm »
I compromised and did Super Speeler's method in a subroutine.  The loop and all the other modules are in this subroutine.  PyroEdit's loader now just executes, copies everything into RAM and sets up all the variables, and then goes to the subroutine until it exits, then quits on out of the whole thing.