Find the Number in Array using Assembly Language | Search Value from Array using Assembly Programming Language
Write a program in assembly language to scan a
value form keyboard and then search it from array of ten values and display the
message if value Found or not Found
Here is an example in Emu8086 Assembly language that prompts
the user to input a value. Search for that value in array of ten integers value
and displays a message whether the value is found or not found
Program Source Code
include "emu8086.inc"
org 100h
.model small
.data
num db 10,12,3,4,5,6,11,7,8,9
msg db "Enter Number $"
msg1 db 10,13, "number is Found $"
msg2 db 10,13, " number is not Found $"
value db ?
.code
mov ax,@data
mov ds,ax
lea dx,msg
mov ah, 09h
int 21h
; read value from keyboard
mov ah, 01h
int 21h
sub al, '0' ; convert ASCII digit to binary
mov value, al
lea si,num ; mov si offset num
mov cx,10
mov al,value
Searching:
mov bl,[si]
cmp al,bl
jz NumFound
inc si
Loop Searching
mov dx,offset msg2
mov ah,9
int 21h
.EXIT
NumFound:
mov dx,offset msg1
mov ah,9
int 21h
.EXIT
ret
Output Code
Explain the program how it work
1. The program
defines an array of ten integer value and two message to display depending on
whether the value is found or not found
2. The program
prompts the user to input a value to search for
3. The program
reads the values from the keyboard and converts it from ASCII to binary
4. The program
loops though the array and compare each element to the value. If the value is
found the program jumps to the ‘found’ label. If the end of the array is
reached without finding the value, the program displays the not found message
5. If the
value is found the program displays the found message and exits
6. The program
exits and return to DOS screen
Post a Comment