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

```
here is a better way of doing this loop
it goes bc number of times

loop:
;do stuff
;
dec bc ;decrease counter
ld a,b ;a=highbit
or c ;b or c if both are zero then the zero flag is
set
jp nz,loop
;done with loop

--- Kouri <Kouri@ucdavis.edu> wrote:
>
> 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
>
> :)
>
> ----- Original Message -----
> From: "Laurens Holst" <laurensh1@yahoo.com>
> To: <assembly-83@lists.ticalc.org>
> Sent: Friday, December 10, 1999 7:15 AM
> Subject: A83: Re: Re: Re: Problem with a program
>
> And DJNZ is 16-bit.
> But using a trick (see below), you can make 16-bit
> loops which are almost as
> fast as DJNZ.
>
> Trick: input=nr. of loops in BC
>
> ld a,c    ;preloop-part
> ld c,b
> ld b,a
> dec bc
> inc b
> inc c
> Loop:    ;the loop itself
> xxx
> xxx
> xxx
> djnz Loop
> dec c
> jr nz,Loop
>
> Ofcourse you can shorten this by precalculating BC.
>
> ~Grauw
>
>
>

__________________________________________________
Do You Yahoo!?
Thousands of Stores.  Millions of Products.  All in one place.
Yahoo! Shopping: http://shopping.yahoo.com

```

Follow-Ups: