forked from mohitarora3/assembly_programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary_search.asm
More file actions
80 lines (52 loc) · 1.63 KB
/
binary_search.asm
File metadata and controls
80 lines (52 loc) · 1.63 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
;............................................................................
data segment
array db 1,2,3,4,5
FOUND db 'ELEMENT FOUND $'
NOT_FOUND db 'ELEMENT NOT FOUND $'
ele db 2 ;ele variable stores the element to be searched
first dw 0
last dw 4
two db 2
data ends
;............................................................................
;.............................................................................
code segment
assume ds:data, cs:code
start:
mov ax,data
mov ds,ax
next:
mov ah,0
mov ax,first
add ax,last
div two ;performing divide operation
mov ah,0
mov si,ax
mov al,array[si]
cmp al,ele
je present
;if element is present in the array
jl right_half ;search in right half
dec si
mov last,si
jmp next1
right_half:
inc si
mov first,si
next1:
mov ah,0
mov ax,first
cmp ax,last
jle next
mov dx,offset NOT_FOUND
mov ah,9
int 21h
jmp exit
present:
mov dx,offset FOUND
mov ah,9
int 21h
exit: hlt
code ends
end start
;...............................................................