A82: Looping


[Prev][Next][Index][Thread]

A82: Looping




According to ash school you can do a 16bit loop with the following rutine:

 ld bc,x
loop:
 .
 dec bc
 jr nz,loop

but ... the books I have read about the z80 all says that a 16bit inc/dec
doesn't change the flags. So this won't work. Am I correct?

So how can I make such a rutine most efficiently? Like this

 ld b,x
loop1:
 ld c,b
 ld b,x
loop2:
.
 djnz loop2
 ld b,c
 djnz loop1

or this

 ld bc,x
loop:
 .
 dec bc
 ld a,c
 or a
 jr nz,loop
 ld a,b
 or a
 jr nz,loop

or is it done completely different?

Stefan Sommer
By most known as Stefan The Greatest (Almost) Sommer
     God created my kind - but he forgot to tell me why