171k views
5 votes
I have a masm program that has 2 arrays. They both have 4 values. I do not need inputs since I already have the values provided for me. One array is the points earned in a test and the other array is the points possible. In order to get the average I have to use the formula (points earned/points possible) * 100. I can’t use a loop for this implementation. It has to be a simple masm program. The answers have to be stored in eax and edx

I have a masm program that has 2 arrays. They both have 4 values. I do not need inputs-example-1
User MQoder
by
8.7k points

1 Answer

1 vote


\: \:

Here's a simple MASM program that calculates the average of two arrays without using a loop:

```

.model flat, stdcall

.stack 100h

.data

pointsEarned DWORD 80, 65, 90, 75

pointsPossible DWORD 100, 100, 100, 100

.code

main PROC

mov eax, pointsEarned

mov edx, pointsPossible

; calculate the sum of points earned and points possible

add eax, DWORD PTR [eax+4]

add eax, DWORD PTR [eax+8]

add eax, DWORD PTR [eax+12]

add edx, DWORD PTR [edx+4]

add edx, DWORD PTR [edx+8]

add edx, DWORD PTR [edx+12]

; calculate the average

mov ebx, 100

mul ebx

div edx

; store the result in eax

mov eax, edx

ret

main ENDP

END main

```

This program first loads the addresses of the two arrays into `eax` and `edx`. It then adds up the values in both arrays using `add` instructions. After that, it multiplies the sum of points earned by 100, and divides it by the sum of points possible using the `mul` and `div` instructions. Finally, it stores the result in `eax` and returns.

Note that the program assumes that the arrays are stored in consecutive memory locations, with each value taking up 4 bytes. If your arrays are stored differently, you'll need to adjust the code accordingly.

User Thi Gg
by
7.9k points