Question: Create a procedure that returns the sum of all array elements less than value limit. Return the sum in the EAX register and make sure

Create a procedure that returns the sum of all array elements less than value limit. Return the sum in the EAX register and make sure to preserve appropriate registers. Write a test program that calls the procedure twice (for the two arrays), passing an address to a signed double word array, the size of the array, and the value of limit. Print the two sums. Use the following data: limit SDWORD 40

sortedArr SDWORD 10, 17, 19, 25, 30, 40, 41, 43, 55

unsortedArr SDWORD 10, -30, 25, 15, -17, 55, 40, 41, 43

count1 = LENGTHOF sortedArr

count2 = LENGTHOF unsortedArr

I wrote some code, but evenever I run my program, it always produces an error at L1: mov ebx,[esi]

INCLUDE IRVINE32.INC

.386

.model flat,stdcall

.stack 4096

ExitProcess PROTO, dwExitCode:dword

.data

limit SDWORD 40

sortedArr SDWORD 10, 17, 19, 25, 30, 40, 41, 43, 55

unsortedArr SDWORD 10, -30, 25, 15, -17, 55, 40, 41, 43

count1 = LENGTHOF sortedArr

count2 = LENGTHOF unsortedArr

sum SDWORD ?

.code

main proc

mov esi, offset sortedArr ; index register

mov ecx, count1 ; loop counter

mov ebx,limit

call SumOf

mov sum,eax

call writeint

SumOf Proc

push esi

push ecx

push ebx

mov eax,0

L1:

mov edx,[esi]

cmp edx,ebx ; compare al with limit

jl addToSum ; jump to addToSum if less

add ebx, TYPE sortedArr

loop L1

pop esi

pop ecx

pop ebx

addToSum:

add eax,edx

add ebx, TYPE sortedArr

jmp L1

ret

SumOf ENDP

invoke ExitProcess,0

main endp

end main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!