User Guide
<%27
7UGT
U/CPWCN
80 +DUGZDUHDQG6RIWZDUH,PSOHPHQWDWLRQ([DPSOHV
15 ; c length of data array
16 ; d first element in comparison
17 ; e second element in comparison
18 ; h flag to indicate exchange
19 ; l unused
20 ; ix pointer into data array
21 ; iy unused
22 ;
0000 222600 23 sort: ld (data), hl ; save data address
0003 cb84 24 loop: res flag, h ; initialize exchange flag
0005 41 25 ld b, c ; initialize length counter
0006 05 26 dec b ; adjust for testing
0007 dd2a2600 27 ld ix, (data) ; initialize array pointer
000b dd7e00 28 next: ld a, (ix) ; first element in comparison
000e 57 29 ld d, a ; temporary storage for element
goof dd5e01 30 ld e, (ix+1) ; second element in comparison
0012 93 31 sub e ; comparison first to second
0013 3008 32 jr pc, noex-$ ; if first
> second, no jump
0015 dd7300 33 ld (ix), e ; exchange array elements
0018 dd7201 34 ld (ix+i), d
001b cbc4 35 set flag, h ; record exchange occurred
0010 dd23 36 noex: inc ix ; point to next data element
001f 10ea 37 djnz next-$ ; count number of comparisons
38 ; repeat if more data pairs
0021 cb44 39 bit flag, h ; determine if exchange occurred
0023 20de 40 jr nz, loop-$ ; continue if data unsorted
0025 c9 41 ret ; otherwise, exit
42 ;
7DEOH%XEEOH/LVWLQJ&RQWLQXHG
/RF 2EM&RGH 6WPW 6RXUFH6WDWHPHQW