-
Notifications
You must be signed in to change notification settings - Fork 0
/
binSearch.s
52 lines (39 loc) · 913 Bytes
/
binSearch.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
* Please forgive the lack of comments in this program, they were stripped out
ORG $8000
binSearch: link A6,#0
movem.l A1-A3/D1/D2/D2,-(SP)
move.w 8(A6),D1 *KEY
movea.l 10(A6),A1 *LO
movea.l 14(A6),A2 *HI
cmpa.l A1,A2
BHS next
move #2,CCR
BRA out
next: move.l A1,D2
add.l A2,D2
lsr.l #1,D2
andi.b #$FE,D2
movea.l D2,A3
cmp.w (A3),D1
BNE continue
move.l A3,D0
BRA out
continue: BGT right
subq.l #2,A3
pea (A3)
pea (A1)
move.w D1,-(SP)
JSR binSearch
adda.l #10,SP *pop garbage
BRA out
right: pea (A2)
addq #2,A3
pea (A3)
move.w D1,-(SP)
JSR binSearch
adda.l #10,SP *pop garbage
bra out
out: movem.l (SP)+,A1-A3/D1/D2
unlk A6
rts
end