-
Notifications
You must be signed in to change notification settings - Fork 0
/
lsearch_proc.asm
78 lines (52 loc) · 1.28 KB
/
lsearch_proc.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
; Author - Jatin Rohilla
; Course - MCA 102
; Objective - Implement Linear Search procedure
;data segment
DATA SEGMENT
ARRAY DW 01H, 04H, 16H, 12H, 17H, 21H
ELEMENT DW 17H
INDEX DW ?
TWO DB 2
DATA ENDS
;code segment
CODE SEGMENT
ASSUME DS: DATA, CS:CODE
START:
MOV AX,DATA
MOV DS,AX
; clear AX
MOV AX,0
; set SI=0
MOV SI,0
; CX = array size
MOV CX,6
; moving array base address to BX
MOV BX,OFFSET ARRAY
; call mysearch
CALL MYSEARCH
;halt program
hlt
; a near procedure
MYSEARCH PROC NEAR
SEARCH:
MOV DX,BX[SI]
CMP DX,ELEMENT
JZ FOUND
; as it is word, SI is incremented twice
INC SI
INC SI
LOOP SEARCH
NOTFOUND:
MOV INDEX,-1
JMP DONE
FOUND:
MOV AX, SI
DIV TWO
MOV AH,0
MOV INDEX,AX
JMP DONE
DONE:
RET
MYSEARCH ENDP
CODE ENDS
END START