MRC: Bug

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

Por AuroraMSX

Paragon (1902)

imagem de AuroraMSX

27-10-2004, 09:38

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 Tongue

Not in BASIC you can't! Tongue

Por IC

Hero (557)

imagem de IC

27-10-2004, 12:19

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 Wink

Por anonymous

incognito ergo sum (116)

imagem de anonymous

27-10-2004, 13:34

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.

Por IC

Hero (557)

imagem de IC

27-10-2004, 13:44

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

Por AuroraMSX

Paragon (1902)

imagem de AuroraMSX

27-10-2004, 13:51

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 Wink

You are Smile 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 Smile

Por IC

Hero (557)

imagem de IC

27-10-2004, 14:00

I just proven myself I am dumb Wink
I wasn't really paying attention.. It's recursive...

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

Por NYYRIKKI

Enlighted (5889)

imagem de NYYRIKKI

27-10-2004, 16:15

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:
	adc a,d
	ld (hl),a
	xor a
	inc l
	ret z
	ld e,l
l2:
	adc a,d
	srl e
	jr nz,l2
	jr l1

Por Sonic_aka_T

Enlighted (4130)

imagem de Sonic_aka_T

27-10-2004, 16:26

Uhm, what does this do again?

Por IC

Hero (557)

imagem de IC

27-10-2004, 16:36

compress your todo list perhaps Wink

Por NYYRIKKI

Enlighted (5889)

imagem de NYYRIKKI

27-10-2004, 16:40

Uhm, what does this do again?
I can quarantee, that it is not important thing to know Smile

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