Re: LZ: sorting


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

Re: LZ: sorting



D Melton wrote:
> 
> Does anyone know a short routine to sort a list?  The list is one byte per
> element, one right after the other in memory.  The routine does not
> necessarily have to be that fast, just short.  Thanks for any help.
> 


A simple bubblesort should be good then. This is from "Programming the Z80"
with Rodney Zaks:


Bubble:
 ld (temp),hl
Again:
 ld ix,(temp)
 res 0,h
 ld b,c
 dec b
Next:
 ld a,(ix)
 ld e,(ix+1)
 cp e
 jr nc,NoSwitch
XChange:
 ld (ix),e
 ld (ix+1),d
 set 0,h
NoSwitch:
 inc ix
 djnz Next
 bit 1,h
 jr nz,Again
 ret


I assume that the list starts at HL with the length C.


<pre>
-- 
Real name: Jimmy Mårdell
Email....: mailto:mja@algonet.se
IRC-name.: Yarin
WWW......: http://www.algonet.se/~mja
</pre>


References: