Linear Search in Array – Assembly Program


Write and run a program using 8086 assembly language that searches for a value in an array of 5 elements. The array should be a byte array stored in the memory locations. In case the value is found in the array then location of the element is put in the BL register, else 0 is put in the BL register. For example, if array in the memory is 05 07 1A 09 71 (all numbers are in hexadecimal) and you are looking for (05)h then output of the program will be 1 which will be stored in the BL register. [Dec 2014, Set-2]

DATA SEGMENT
    ARRAY DB 15H, 07H, 1AH, 09H, 01H 
DATA ENDS

CODE SEGMENT
START:

    ASSUME CS:CODE, DS:DATA 
    MOV AX, DATA
    MOV DS, AX 
    
    MOV SI, 0000h
    MOV CX, 5H
    
  NEXT: 
    MOV AL, ARRAY[SI]
    
    CMP AL,05H
    JE RESULT
    
    ADD SI,2   
    LOOP NEXT 
    
    MOV BL, 00H 
    
    MOV AX, 4C00H
    INT 21H 
    
  RESULT:
    MOV BL, 01H  
        
    MOV AX, 4C00H
    INT 21H    
CODE ENDS

END START