Using MASM write an assembly language program that searches through an array of
ID: 655448 • Letter: U
Question
Using MASM write an assembly language program that searches through an array of 10 elements. Copy and paste the template on the next page as the starting point for your work. All you need to add is code; all the necessary data items are already defined.
Input: Your input variables are called query (the search query) and arr (the array).
Output: Your search algorithm should set the following variables in accordance with the results of the search:
- found: set this to 1 if the query was located in the array; leave it as 0 otherwise
- index: the index of the first location in the array where the query was found (zero-based)
- count: the number of times that the query appears in the array
The .DATA segment defines the following variables: query, arr, found, index, count.
Do not define any additional data items; points will be taken off if you do so.
For the maximum score 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.
The template is initialized to search for the value 3 initially. The search should find this value in the array multiple times. Also search for a value such as 10 that is not found in the array to test that logic as well. Either modify the program to give query a different initial value or change the value in memory with WinDbg before the program begins execution.
Upload the final version of the .asm file to the Lab 8 dropbox in D2L.
You may use the template below to help you get started (copy and paste into Notepad or some other plain-text editor of your choice):
; ***********************************************************************
; * File : lab8.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
;Don
Explanation / Answer
DATA SEGMENT
ARR DB 1,4,2,3,9,8,6,7,5,10
LEN DW $-ARR
LARGE DB ?
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA SI,ARR
MOV AL,ARR[SI]
MOV LARGE,AL
MOV CX,LEN
REPEAT:
MOV AL,ARR[SI]
CMP LARGE,AL
JG NOCHANGE
MOV LARGE,AL
NOCHANGE:
INC SI
LOOP REPEAT
MOV AH,4CH
INT 21H
CODE ENDS
END START
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.