Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in assembly language that will - take ten integers (32 bit) in a

ID: 3817696 • Letter: W

Question

Write a program in assembly language that will - take ten integers (32 bit) in an array - add up the elements - calculate the integer average - print out the integers and the resulting sum and average
Use the following set of integers (in decimal):
14   -32     0     7    42   -20    18   300 -123    -6

No Loops!!

This is my code so far, i'm having troube with the division part. Output should show 200 and 20 respectivley.

INCLUDE Irvine32.inc

.data
myArray DWORD 10 DUP (?)
Sum DWORD ?

.code
Main PROC
call Clrscr

call ReadInt
mov[myArray+0],eax
call ReadInt
mov[myArray+4],eax
call ReadInt
mov[myArray+8],eax
call ReadInt
mov[myArray+12],eax
call ReadInt
mov[myArray+16],eax
call ReadInt
mov[myArray+20],eax
call ReadInt
mov[myArray+24],eax
call ReadInt
mov[myArray+28],eax
call ReadInt
mov[myArray+32],eax
call ReadInt
mov[myArray+36],eax

mov eax,0
add eax,[myArray+0]
add eax,[myArray+4]
add eax,[myArray+8]
add eax,[myArray+12]
add eax,[myArray+16]
add eax,[myArray+20]
add eax,[myArray+24]
add eax,[myArray+28]
add eax,[myArray+32]
add eax,[myArray+36]

mov Sum,eax
call WriteInt
call CRLF

mov eax,ecx
mov ebx,10
xor edx,edx
div ebx
call WriteInt
call CRLF

exit
main ENDP

END main

Explanation / Answer

I have modified the code. The modified statements are in BOLD font:-

Code:-

INCLUDE Irvine32.inc

.data
myArray DWORD 10 DUP (?)
Sum DWORD ?

.code
Main PROC
call Clrscr

call ReadInt
mov[myArray+0],eax
call ReadInt
mov[myArray+4],eax
call ReadInt
mov[myArray+8],eax
call ReadInt
mov[myArray+12],eax
call ReadInt
mov[myArray+16],eax
call ReadInt
mov[myArray+20],eax
call ReadInt
mov[myArray+24],eax
call ReadInt
mov[myArray+28],eax
call ReadInt
mov[myArray+32],eax
call ReadInt
mov[myArray+36],eax

mov eax,0
add eax,[myArray+0]
add eax,[myArray+4]
add eax,[myArray+8]
add eax,[myArray+12]
add eax,[myArray+16]
add eax,[myArray+20]
add eax,[myArray+24]
add eax,[myArray+28]
add eax,[myArray+32]
add eax,[myArray+36]

mov Sum,eax
call WriteInt
call CRLF

mov eax,Sum
mov ebx,10
xor edx,edx
div ebx

mov ecx,eax
call WriteInt
call CRLF

exit
main ENDP

END main

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote