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


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

> For a fancier way to do it, you could just....
> ld bc, 0FFFFh
> Loop:
> ; CODE
> cpi
> 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.

Nice, indeed. If you don't use HL (alot of routines don't or else you can
use the -a little slower- DE), this is indeed also a very good solution.

>   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'

Yes, pe is the opposite. Ya know, it is a 1-bit flag (called
parity/overflow, but is has even got three uses!), which can only have two
states. 1 and 0. So if there is nothing 'inbetween', and it would be a bit
strange if there was no difference between parity even (pe) and parity odd
(po). By the way, in this case the bit has nothing to do with parity nor
overflow. When you use one of the instructions LDD, LDDR, CPD, CPDR, this
bit simply indicates that register BC has reached zero (the bit will then be
reset). With LDI, LDIR, CPI, CPIR, this bit is set when at the beginning of
the instruction BC-1=0.

But jr pe won't work, 'cause you can only use z, nz, c and nc with jr. So
that should then be:

ld bc, #FFFF
    ; CODE
jp pe,Loop

But err... it's still way slower than my "djnz"-solution... look:

DJNZ way: 13 T-states (three bytes, once per 256 loops 24 T-states)
CPI way: 16+10 = 26 T-states (four bytes -three using jr/ret but slower:
B OR C way: 6+4+4+10 = 24 T-states (four bytes)

So actually your way is even slower than the 'nicest' way (which also
doesn't change HL), the B OR C way. But if you already had a DEC HL in your
routine, you can combine it and you will gain 4 T-states over the B OR C
way. But still, although not very clear, my way is the fastest. (yeeh!)


          email me: or ICQ: 10196372
             visit the Datax homepage at
MSX fair Bussum / MSX Marathon homepage: