; PROGRAM: SEARCH ELEMENT IN AN ARRAY
read macro num
mov ah, 01h
int 21h
mov bh, al
int 21h
mov bl, al
sub bh, 30h
mov al, 0ah
mul bh
sub bl, 30h
add al, bl
mov num, al
endm
print macro s
mov ah, 09h
mov dx, offset s
int 21h
endm
data segment
msg db 'Enter Limit: $'
dot db '. $'
comma db ', $'
enter db 'Enter elements: $'
srch db 'Search Element: $'
pos db 3 dup('$')
msg_y db 'Element found at position: $'
msg_n db 'Element NOT Found!$'
nl db 0dh,0ah,'$'
limit db 00h
cnt dw 00h
arr db 50 dup('$')
num db 3 dup('$')
ele db ?
data ends
code segment
assume cs:code, ds:data
start:
mov ax, data
mov ds, ax
mov es, ax
print msg
read limit
mov cl, limit
mov ch, 00h
print nl
print enter
mov si, offset arr
READARR:
read ele
mov al, ele
mov [si], al
inc si
print comma
loop READARR
print nl
print srch
read ele
mov bx, 00h
mov si, offset arr
ARRSEARCH:
cmp bl, limit
jge ELENOTFOUND
mov dh, [bx][si]
cmp dh, ele
je ELEFOUND
inc bx
jmp ARRSEARCH
ELEFOUND:
print nl
print msg_y
mov al, [bx][si]
mov ah, 00h
mov si, offset pos
call hex2ascii
print pos
jmp FINISH
ELENOTFOUND:
print msg_n
FINISH:
mov ah, 4ch
int 21h
hex2ascii proc near
mov cx, 0000h
REPDIV:
mov dx, 0000h
mov bx, 000ah
div bx
add dl, 30h
push dx
inc cx
cmp ax, 000ah
JGE REPDIV
cmp al, 00h
je SKIP0
add al, 30h
mov [si], al
inc si
SKIP0:
SAVEASCI:
pop dx
mov [si], dl
inc si
loop SAVEASCI
STOP1:
mov [si], '$'
ret
hex2ascii endp
code ends
end start
**************************
OUTPUT
Z:\S5IT\masm>arr_search
Enter Limit: 04
Enter elements: 01, 02, 03, 04,
Search Element: 03
Element found at position: 3
**************************
0 comments:
Post a Comment