Question: this is assembly language. COMMENT ! Create a procedure named FindThrees that returns 1 if an array has three consecutive values of 3 somewhere in
this is assembly language.
COMMENT ! Create a procedure named FindThrees that returns 1 if an array has three consecutive values of 3 somewhere in the array. Otherwise, return 0. The procedure's input parameter list contains a pointer to the array and the array's size. Use the PROC directive with a parameter list when declaring the procedure. Preserve all registers (except EAX) that are modified by the procedure. Write a test program that calls FindThrees several times with different arrays. !
.386 .model flat,stdcall .stack 4096 ExitProcess proto,dwExitCode:dword FindThrees proto aPtr:PTR SDWORD, arraySize:DWORD
.data strSuccess BYTE "Success.", 0 strFailure BYTE "Failure.", 0 Array1 sdword 4, 6, 3, 3, 2, 5 ; false Array2 sdword 3,3,3,9,5 ; true Array3 sdword 1,2,3,3,4,3,3,3,9 ; true Array4 sdword 1,2,4,-4,-5,9 ; false
.code main proc invoke FindThrees, ADDR Array1, LENGTHOF Array1 ;invoke FindThrees procedure for Array 1 ;invoke FindThrees procedure for Array 2 ;invoke FindThrees procedure for Array 3 ;invoke FindThrees procedure for Array 4
invoke ExitProcess,0 main endp
FindThrees proc, aPtr:PTR SDWORD, arraySize:DWORD ;push esi array register ;push ecx ;;;to keep track of size of array ;initialize repetition count by moving 0 into eax ;move the aPtr into the esi register ;move the arraySize into the ecx count register
L1: ;begin loop1 by comparing the sdword ptr esi and 3 ;jump to loop2 if the previous compare are not equal ;increment the eax count, if you reach 3 then you f ;compare 3 and eax register ;jump if equal to success ;;;;return with success ;jump to L2A ;;;; keep counting
L2: ;reset the number of 3s count by moving a 0 into eax L2A: ;;;; point to next array element since you did not find 3 threes yet, this line should have the loop tag only ;add 4 to the esi register ;loop back to L1 mov edx, OFFSET strFailure ;;;;Send Failure Message call WriteString ;;;;Irvine Library Method ;jump to L3 ;;;;failure!
success: ;move a 1 into eax ;;;; return True mov edx, OFFSET strSuccess ;;;;Send Success Message call WriteString ;;;;Irvine Library Method
L3: ;;;;3 threes were not found ;pop the ecx register ;pop the esi register ;return FindThrees endp
end main
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
