using MASM write an assembly language program that searches through an array of
ID: 655488 • Letter: U
Question
using MASM write an assembly language program that searches through an array of 10 elements.
keep intermediate results in registers and only set found and count at the end of the search process. You may set index as soon as its value is known.
; ***********************************************************************
; * File : arrSearch.asm
; * Author : your name here
; * Description: This program searches an array
; ***********************************************************************
.386
.MODEL FLAT
ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD
PUBLIC _start ; make procedure _start public
; ***********************************************************************
; * Data Segment
; ***********************************************************************
.DATA
query DWORD 3 ; search query
arr DWORD 1,2,3,4,5,1,3,5,7,9 ; creating array of 10 4-byte DWORDs
found DWORD 0 ; 1 if query located in array, otherwise 0
index DWORD 0 ; index of first appearance of query in array
count DWORD 0 ; number of times query appears in array; ***********************************************************************
; * Stack Segment
; ***********************************************************************
.STACK 4096
; ***********************************************************************
; * Code Segment
; ***********************************************************************
.CODE
_start PROC NEAR32 ; start procedure called _start
;
;FILL IN YOUR SOLUTION CODE HERE
;
;
;
EVEN ; Make rest of code aligned on an even-addressed byte
exit: INVOKE ExitProcess, 0 ; like return( 0 ); in C
_start ENDP ; end procedure _start
END
Explanation / Answer
DIM1 EQU 10
MOV DI, 0
MOV AL,query
MOV CX, DIM1
LAB1:CMP arr[DI],AL
JNE PASS
INC count
MOV found 1
PASS:INC DI
DEC CX
CMP CX,0
JNZ LAB1
MOV found 0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.