# MRC: Bug

Página 3/4
1 | 2 | | 4

recursion my but..
The sub routine at 1000 calls itself. I don't know how *you* would call such a construction, but it *is* recursion.

it's mainly a loop, but the loop var is constantly being changed

I can't help it that BASIC is such a crappy language to write recursive algorithms in 8)

even with djnz you can make such a loop by simply changing the B reg Not in BASIC you can't! imho it does the same as this:

```1000 V(N)=Z: N=N*2: L=L+1: IF L < 8 then goto 1000:N=N+1: Z=Z+1
1010 N=(N-1)/2: Z=Z-1: L=L-1: RETURN
```

But I might be wrong about this yes, everything after the GOTO isn't executed, and in the original code there was an extra GOSUB1000. So while your GOTO thingy does speed up the first part of the routine, the routine still needs recursion to function.

1000 V(N)=Z: N=N*2: L=L+1: IF L < 8 then goto 1000 else N=N+1: Z=Z+1
1010 N=(N-1)/2: Z=Z-1: L=L-1: RETURN

and the extra gosub does just return eh.. cauz the L = 8 at that point (so why use the extra gosub while it isn't really needed).

but ok.. the heck with this... back to work

imho it does the same as this:

```1000 V(N)=Z: N=N*2: L=L+1: IF L < 8 then goto 1000:N=N+1: Z=Z+1
1010 N=(N-1)/2: Z=Z-1: L=L-1: RETURN
```

But I might be wrong about this You are Your routine only fills V(0), V(2), V(4), V(8) .. V(128), and misses all other entries in V(). Then, when L equals 8, line 1010 is executed and the routine RETURNs to the call earlier in the program and all other entries in V() are left 0.

The fun in my routine is in the use of GOSUBs I just proven myself I am dumb I wasn't really paying attention.. It's recursive...

(and to add to it: forget that goto stuff cauz it's nonsense)

Ok, here is really fast version:

```10 DEFINTA-Y
20 A\$="AF572100C08A77AF2CC85D8ACB3B20FB18F3"
30 FORI=0TO17:POKE&HD000+I,VAL("&H"+MID\$(A\$,I*2+1,2)):NEXTI
40 DEFUSR=&HD000:A=USR(0)
50 OPEN"TODO.TXT"FORINPUTAS#1
60 IFEOF(1)THENCLOSE:OPEN"TODO.PCK"FOROUTPUTAS#1:PRINT#1,Z1:PRINT#1,Z0:END
70 A=ASC(INPUT\$(1,1)):Z1=Z1+PEEK(&HC000+A):Z0=Z0+8-PEEK(&HC000+A)
80 GOTO60
```

... and here is tokenized version of the ML routine:

```
xor a
ld d,a
ld hl,#C000
l1:
ld (hl),a
xor a
inc l
ret z
ld e,l
l2:
srl e
jr nz,l2
jr l1
```

Uhm, what does this do again?

compress your todo list perhaps Uhm, what does this do again?
I can quarantee, that it is not important thing to know Página 3/4
1 | 2 | | 4