Re: A83: rep stosw


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

Re: A83: rep stosw



>Is there an instruction corresponding to "rep stosw" (8086
>processor) on the z80?
>
>In other words, is there a shorter/faster version to 
>
>  mov de,bytes_to_clear
>loop:
>  ld (hl),a
>  inc hl
>  dec de
>  dj nz, loop

The best way to do it is this:

   ld bc,bytes_to_clear-1
   ld d,h
   ld e,l
   inc de
   ld (hl),a
   ldir

The LDIR instruction is actually more like the 8086 "rep movsw",
but this makes it repeatedly copy the previous byte over the
current one, simulating the "rep stosw".

By the way, I don't think the code you listed in your message
works at all.  The djnz instruction (maybe you meant jr nz) always uses 
only the B register, so your loop could run the wrong number
of times.  In addition, "dec de" does not set the status flags,
so you must do "ld a,d \ or e" afterwards if you want to test if
DE is zero.

______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com