Zilog Z08470 User Manual

Page 42

Advertising
background image

Hardware and Software Implementation

UM008007-0715

30

Z80 CPU
User Manual

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

dd2a260
0

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

;

0026

43

flag:

equ

0

; designation of flag bit

0026

44

data:

defs

2

; storage for data address

45

end

Table 2. Bubble Listing (Continued)

Location

Object
Code

Statement

Source Statement

Advertising
This manual is related to the following products: