%OUT-------------------------------------------------------------------------
%OUT- Performs linear Search on an array accepted from user
%out- input: Enter the key to find
%out- output: Array index(index starts from 00)[if found]
%out – author: Ayon and Ariyam
%OUT-------------------------------------------------------------------------
if1
include macrolib.lby ;contains common macros
endif
.model small
.stack
.data
array db 11 dup(?) ;array to be sorted
count dw 1 dup(?) ;array length
msg db " Enter No. ","$"
i_msg db "How many elements? ","$"
yes db "Data found at array index:","$"
no db "Data not present!","$"
find db " Enter element to search: ","$"
i_p db "Original array: ","$"
.code
main proc
;accept data
mov ax,@data
mov ds,ax
showmsg i_msg
input
lea bx,count
mov [bx],al
input_array array,count,msg
showmsg i_p
mov cx,count
mov si,0000h
lp:
mov bh,array[si]
output
space
inc si
loop lp
showmsg find
input ;call input macro, accept the data to search
mov cx,count
mov si,00h
lp1:
cmp al,array[si]
jz found
inc si
loop lp1
;not found
mov bh,-1h
space
showmsg no
jmp op_display
found:
push si
space
showmsg yes
pop si
mov bx,si
mov bh,bl
op_display:
space
output ;macro output
exit
main endp
end main
No comments:
Post a Comment
Do you think this information useful or was not up to the mark? Comment if you have any advices or suggestions about the post.