Problem 4 --------- SortMainLoop: ld bc,LIST SortLoop: ld a,(bc) or a ret z ;done? ld h,b ;copy pointer ld l,c ld d,b ld e,c SortFind: push bc ;point hl to next string ld bc,16 add hl,bc pop bc ld a,(hl) or a jr z,SortSwap ;next string==null? push de push hl SortFindLoop: ld a,(de) ;is (de) bigger or smaller than (hl)? cp (hl) inc hl inc de jr z,SortFindLoop pop hl pop de jr c,SortInOrder ;smaller (already in order) ld d,h ;we've found a new smaller one ld e,l ;now we'll check the rest against it. SortInOrder: jr SortFind ;check the next string SortSwap: ld l,16 SortSwapLoop: ld a,(de) ;swap one byte push af ld a,(bc) ld (de),a pop af ld (bc),a inc bc ;next byte inc de dec l jr nz,SortSwapLoop ;16 times jr SortLoop ;now search for the next-smallest string ;Returns: ;A=$00, F=$44 (s=0, z=1, 5=0, h=0, 3=0, p=1, n=0, c=0) ;BC=DE=pointer to null terminator ;H=D=B, L=$00 ;LIST is sorted