News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

BASIC: ON someval GOTO line100, line200, line300

Started by jj2007, May 20, 2024, 09:58:56 AM

Previous topic - Next topic

jj2007

Just for fun, and inspired by Steve's GW-BASIC thread, I made two new macros mimicking BASIC's ON someval GOTO 100, 200, 300 command (ecx is the index):

.code
p0:
  deb 4, "P0", eax
  retn
p1:
  deb 4, "P1", eax
  retn
...
g0:
  deb 4, "G0", eax
  jmp @back
g1:
  deb 4, "G1", eax
  jmp @back
...

  For_ ecx=0 To 2
    lea eax, [ecx+100]        ; pass a value in eax
    OnIndexCall ecx, p0, p1, p2
  Next
  For_ ecx=0 To 2
    lea eax, [ecx+1000]        ; pass a value in eax
    OnIndexGoto ecx, g0, g1, g2
    @back:
  Next

Output:
P0      eax             100
P1      eax             101
P2      eax             102
G0      eax             1000
G1      eax             1001
G2      eax             1002

Source attached. ON ... GOTO ... is not the most beautiful command, but it can actually be handy.