Answer:
Let’s identify variables needed for this program.
First variables will be the one which will hold the values present in the Given Numbers in Array list and key of 16-bit and it will be array ARR and KEY. variables will be holding the Messages MSG1 “KEY IS FOUND AT “, RES ” POSITION”, 13, 10,” $” and MSG2 ‘KEY NOT FOUND!!!.$’ to be printed for the User. Other variables will be holding Length of the Array and it will be LEN, So in all Six variables.
The identified variables are ARR, KEY, LEN, RES, MSG1 and MSG2.
DATA SEGMENT
ARR DW 0000H,1111H,2222H,3333H,4444H,5555H,6666H,7777H,8888H,9999H
LEN DW ($-ARR)/2
KEY EQU 7777H
MSG1 DB "KEY IS FOUND AT "
RES DB " POSITION",13,10," $"
MSG2 DB 'KEY NOT FOUND!!!.$'
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
MOV BX,00
MOV DX,LEN
MOV CX,KEY
AGAIN: CMP BX,DX
JA FAIL
MOV AX,BX
ADD AX,DX
SHR AX,1
MOV SI,AX
ADD SI,SI
CMP CX,ARR[SI]
JAE BIG
DEC AX
MOV DX,AX
JMP AGAIN
BIG: JE SUCCESS
INC AX
MOV BX,AX
JMP AGAIN
SUCCESS: ADD AL,01
ADD AL,'0'
MOV RES,AL
LEA DX,MSG1
JMP DISP
FAIL: LEA DX,MSG2
DISP: MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
In this Assembly Language Programming, A single program is divided into four Segments which are 1. Data Segment, 2. Code Segment, 3. Stack Segment, and 4. Extra Segment. Now, from these one is compulsory i.e. Code Segment if at all you don’t need variable(s) for your program.if you need variable(s) for your program you will need two Segments i.e. Code Segment and Data Segment.
Explanation:
The attached Logic is a C like Program to conduct a binary search we need small Algorithm Shown above in a very simple way, So Just we will covert the logic into Assembly There are many things uncommon in the programing Language. There are No While Loops or Modules but this things are to be implemented in different ways.