请用英特尔8086汇编语言实现对数组的查找
时间: 2024-05-04 10:16:02 浏览: 112
Sure, I'd be happy to help you with that! Here's a sample code snippet that shows how to search for an element in an array using the Intel 8086 assembly language:
```
.MODEL SMALL
.STACK 100H
.DATA
ARRAY DB 10, 20, 30, 40, 50 ; Define a sample array
SIZE DB 5 ; Define the size of the array
SEARCH DB 30 ; Define the value to be searched
.CODE
MAIN PROC
MOV AX, @DATA ; Initialize DS register
MOV DS, AX
MOV BL, SEARCH ; Load the search value into BL register
MOV CX, SIZE ; Load the size of the array into CX register
MOV SI, 0 ; Set the starting index of the array to 0
SEARCH_LOOP:
CMP BYTE PTR [ARRAY+SI], BL ; Compare the current array element with the search value
JE FOUND ; If the element is found, jump to FOUND label
INC SI ; Increment the index
LOOP SEARCH_LOOP ; Repeat the process until all elements are searched
NOT_FOUND:
MOV AH, 4CH ; Exit code for DOS
INT 21H
FOUND:
MOV AH, 09H ; Print message code for DOS
MOV DX, OFFSET MSG ; Load the OFFSET of the message to be printed
INT 21H
MOV AH, 4CH ; Exit code for DOS
INT 21H
MSG DB 'Element found in array!', '$' ; Define the success message
MAIN ENDP
END MAIN
```
This code initializes an array of integers and defines the size of the array and the value to be searched. It uses a loop to iterate through the elements of the array and compares each element with the search value until a match is found. If the element is found, the code prints a success message and exits the program. Otherwise, it exits the program without printing any message.
阅读全文