A83: Re: Re: Re: Re: Re: Problem with a program


A83: Re: Re: Re: Re: Re: Problem with a program

> What do you mean djnz is 16-bit? That it is a 16-bit instruction?
> Anyway, if you want a really, really, really  long loop, why stop with 2
registers? :)
> xor a
> ld b,a
> ld c,b
> ld d,c
> ld e,d
> ld h,e
> ld l,h
> Loop:
> djnz Loop
> dec a \ jr nz,Loop
> dec c \ jr nz,Loop
> dec d \ jr nz,Loop
> dec e \ jr nz,Loop
> dec h \ jr nz,Loop
> dec l \ jr nz,Loop

Hmm that won't work. You will need to do some more precalculating.
Example (in the case of a 16-bit loop using the above):

What if you want to repeat #100 times, eh? You swap that, B=0, C=1. You
start DJNZ. At the end, you have done 256 loops. C will be decreased, is
zero, routine stops. So far so good. But what if you want to repeat #106
times, for example? Will be swapped, B=6, C=1, DJNZ will repeat six times, C
will be decreased, and oh no! It stops! Only 6 repeats, that's no good. At
first, I solved this problem by precalculating the value in BC and putting
it directly into it using LD BC,nnnn. However, this was not looking very
well, and besides, often the value of BC wasn't fixed. So I made a
construction using a conditional jump. After a while I put my routine on the
MSX Mailinglist, and then Maarten ter Huurne told me this could also be done
by simply issueing a DEC BC, INC B, INC C.

> :)

You're fudeba.


          email me: laurensh@geocities.com or ICQ: 10196372
             visit the Datax homepage at http://datax.cjb.net/
MSX fair Bussum / MSX Marathon homepage: http://msxfair.cjb.net/

Follow-Ups: References: