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


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

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




For a fancier way to do it, you could just....

	ld 	bc, 0FFFFh
Loop:
	push	bc      ; Only if you trash it
; CODE
	pop	bc      ; Only if you trash it
	      ; push hl ; Only if you need hl
	cpi
	      ; pop  hl ; Only if you need hl
	ret	po      ; or do  "jr  po, label"
	jr	Loop

  But fancier is not always better.  This should work
fine but it works better for a small delay loop (take
out the push bc, ect...) and if you don't need hl.

  Would 'pe' work the opposite of 'po'? If so then
that would help by changing the end to
   jr  pe, loop
and taking out the 'ret po'


Jimmy


--- Scott Dial <wrath@calc.org> wrote:
> 
> That is a horrible way to do a 16-bit counter for a
> loop. Observe the
> following:
> 
>    ld bc,$FFFF ;Number of loops
> Loop:
>    push bc ;Usually have to do this
> 
> ...
> 
>    pop bc
>    dec bc
>    ld a,c
>    or b
>    jr nz,Loop
> 
> 
> Laurens Holst wrote:
> > 
> > > 65,535 even =)
> > >
> > > Actually, you could just use a 16-bit register
> to control a DJNZ loop (you
> > > CAN do that can't you?...lol) and do all the
> tough mathematics in the OP
> > > registers. Generating 100,000 random numbers on
> an 8Mhz chip will be slow
> > no
> > > matter :)
> > 
> > The Z80 in the TI-82/83(+)/85/86 runs at 6MHz, not
> 8.
> > 
> > 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
> 
> -- 
> Scott "_Wrath_" Dial
> wrath@calc.org
> ICQ#3608935
> TimeCity AI Guy II - www.timecity.org
> Member of TCPA - tcpa.calc.org
> __________________________________________
> NetZero - Defenders of the Free World
> Get your FREE Internet Access and Email at
> http://www.netzero.net/download/index.html
> 
> 

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


Follow-Ups: