Categories
- 4th semester (27)
- 5th semester (3)
- ADA (13)
- Assembly Level Language (12)
- BE (45)
- C Language Programming (5)
- C language (20)
- C++ Language (5)
- CCP Lab programing (3)
- Computer Programming Lab (3)
- DAA Lab Programming (13)
- Data Structure and C++ laboratory Program (6)
- Data Structure and C++ labotary Program (5)
- Design and Analysis of algorithm (14)
- First Year (5)
- MASM (12)
- Microprocessor (12)
- Microprocessor lab program (12)
- System Software & OS Laboratory (5)
- Unix program (4)
- bachelor of engineering (30)
- basic (1)
- basic mathematics (2)
- beginners (10)
- c++ program (9)
- calculations (7)
- computer science (30)
- downloadable (5)
- engineering syllabus (4)
- simple program (6)
Trend Posts
Blogger news
Author
Followers
Blog Archive
-
▼
2014
(37)
-
▼
February
(12)
- a program to create a file (input file) and to del...
- Read a pair of input co-ordinates in BCD and move ...
- Write a program to simulate a Decimal Up-counter t...
- Read the current time from the system and display ...
- Compute nCr using recursive procedure. Assume that...
- Read your name from the keyboard and display it at...
- Read two strings, store them in locations STR1 and...
- Reverse a given string and check whether it is a p...
- Read an alphanumeric character and display its equ...
- Sort a given set of ‘n’ numbers in ascending order...
- Write two ALP modules stored in two different file...
- Search a key element in a list of ‘n’ 16-bit numbe...
-
▼
February
(12)
Friday, February 21, 2014
ASSUME
DS: DATA,
CS: CODE
DATA
SEGMENT ;
start of data segment
NUM
DW 1234H,5678H,6256H,7321H,8454H ; 5 elements
stored in array NUM
COUNT
DW 05H ;
Total
number of elements stored in array (n)
KEY
DW 3456H ;
key element to be searched
MSG1 DB 10, 13, 'KEY
FOUND', '$' ;
message to be displayed on the screen
MSG2 DB 10, 13, 'KEY NOT FOUND', '$'
DATA
ENDS ; end of data
segment
CODE SEGMENT ;
start
of code segment
START: MOV
AX, DATA
MOV
DS, AX ; initializing
data segment
XOR
AX, AX ; clear
AX register contents to store
the mid value
MOV
BX, 1 ; Initialize BX =
1 (Low value)
MOV
DX, COUNT ; Store high value
in DX register (here n=5)
MOV
CX, KEY ; CX contains
value to be searched.
AGAIN: CMP BX, DX ; compare low and
high value
JA
NOTFOUND ; if low value > high value then display key not found
MOV
AX, BX ; AX contains low
value
ADD
AX, DX ; add low and
high value
SHR AX, 1 ; Divide by 2 to
find mid value
MOV
SI, AX ; move mid value
to SI
DEC SI ; decrement SI
ADD SI, SI ; add SI and SI to find the actual mid position of array
CMP
CX, NUM[SI] ;
compare Key
element and middle element of array
JE FOUND ; if equal,
display key has found.
JA
ABOVE ;
if key element is greater than middle element of
;
array,
then
jump to ABOVE
location, to search
;
element from mid to high end side


JMP
AGAIN ;
jump
to AGAIN, to compare next element


JMP AGAIN ; jump to AGAIN to compare next
element.
FOUND: MOV
DX, OFFSET MSG1 ; if found print message MSG1,
whose
offset is in DX
MOV
AH, 09H ; using 09H
service no. with DOS 21H intrpt.
INT
21H
JMP
STOP ;
jump
to stop and terminate
NOTFOUND: MOV DX, OFFSET MSG2 ; if
not found print message MSG2
MOV AH, 09H ; using 09H
service no. with DOS 21H intrpt.
INT 21H
INT 21H
CODE
ENDS ; end of code segment
END
START ;
end of program
Output:
Sample
input : 3456H
Sample
input : 1456H (Change the key
element used in the program and save it)
D:\MASM>
Masm 1a.asm;
D:\MASM>
Link 1a.obj;
D:\MASM>
1a.exe
KEY NOT FOUND
Or
we
can Debug the program using
D:\MASM>
TD 1a.exe
Then
press F7 to trace the program (line
by line execution) or press F9 to
run the program in one operation.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment
You are very Important to Us...
STAY TUNE...