-
Notifications
You must be signed in to change notification settings - Fork 0
/
01.BinarySearch.asm
61 lines (57 loc) · 1.13 KB
/
01.BinarySearch.asm
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
53
54
55
56
57
58
59
60
61
; 1. Design and develop an assembly language program to search a key element “X” in a list of ‘n’
; 16-bit numbers. Adopt Binary search algorithm in your program for searching.
.model small
.stack
.data
exit macro
mov ah, 4ch
int 21h
endm
disp macro msg
mov ah, 09h
lea dx, msg
int 21h
endm
a dw 10h, 20h, 30h, 40h, 50h
n dw ($-a)/2
key dw 40h
l dw ?
h dw ?
mid dw ?
msg1 db "Successful Search$"
msg2 db "Unsuccessful Search$"
.code
mov ax, @data
mov ds, ax
mov l, 0
mov ax, n
dec ax
mov h, ax
mov ax, key
back:
mov si, l
cmp si, h
jg stop
add si, h
shr si, 1
mov mid, si
shl si, 1
cmp ax, a[si]
jne next1
disp msg1
exit
next1:
jg next2
mov bx, mid
dec bx
mov h, bx
jmp back
next2:
mov bx, mid
inc bx
mov l, bx
jmp back
stop:
disp msg2
exit
end