Question: PLEASE READ CAREFULLY BEFORE YOU POST ANSWER. PLEASE FOLLOW THE INSTRUCTION. PLEASE DON'T CHANGE MY FORMAT, I ONLY NEED TO FIX THE ERROR. I DON'T
PLEASE READ CAREFULLY BEFORE YOU POST ANSWER.
PLEASE FOLLOW THE INSTRUCTION.
PLEASE DON'T CHANGE MY FORMAT, I ONLY NEED TO FIX THE ERROR. I DON'T WANT TO USE SOMEONE'S CODE FOR MY ASSIGNMENT.
THIS IS AN ASSEMBLY CODE, NOT C, C++, or JAVA.
Write a complete program that: 1. Prompt the user to enter 10 numbers. 2. save those numbers in a 32-bit integer array. 3. Print the array with the same order it was entered. 3. Calculate the sum of the numbers and display it. 4. Calculate the mean of the array and display it. 5. Rotate the members in the array forward one position for 9 times. so the last rotation will display the array in reversed order. 6. Print the array after each rotation. check the sample run. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Don't use any shift or rotate instructions which we have not covered yet. You need to use loops and indexed addressing. All you work should be on the original array. Don't make a copy of the array at any time. Add comments to make your program easy to read. check the reburic befoe you submit.
Sample Run:
Please enter a number: 2 Please enter a number: 3 Please enter a number: 4 Please enter a number: 5 Please enter a number: 6 Please enter a number: 7 Please enter a number: 8 Please enter a number: 9 Please enter a number: 0 Please enter a number: 10 The sum is: 54 The mean is: 5 4/10 The original array: 2 3 4 5 6 7 8 9 0 10 After a rotation: 10 2 3 4 5 6 7 8 9 0 After a rotation: 10 0 2 3 4 5 6 7 8 9 After a rotation: 10 0 9 2 3 4 5 6 7 8 After a rotation: 10 0 9 8 2 3 4 5 6 7 After a rotation: 10 0 9 8 7 2 3 4 5 6 After a rotation: 10 0 9 8 7 6 2 3 4 5 After a rotation: 10 0 9 8 7 6 5 2 3 4 After a rotation: 10 0 9 8 7 6 5 4 2 3 After a rotation: 10 0 9 8 7 6 5 4 3 2 Press any key to continue . . .
My code
INCLUDE Irvine32.inc
.data
list1 DWORD 10 DUP(0) s1 byte "Please enter a number: ", 0 s2 byte "The sum is: ", 0 s3 byte "The mean is: ", 0 s4 byte "The original array: ", 0 s5 byte "After a rotation: ", 0 var DWORD 0 sum DWORD ? numofarray DWORD ?
.code main proc
mov ecx, 10 mov edx, offset s1 mov ebx, 0 L1: call writestring call readdec mov [list1 + ebx], eax add ebx, 4 LOOP L1 mov ecx, lengthof list1 mov ebx, 0 mov edx, offset s4 call writestring L2: mov eax, [list1 + ebx] call writedec mov al, ' ' call writechar add ebx, 4 LOOP L2 call crlf mov ecx, lengthof list1 mov eax, 0 mov ebx, 0 mov edx, offset s2 call writestring L3: add eax, [list1 + ebx] add ebx, 4 LOOP L3 call writedec call crlf mov edx, offset s3 call writestring mov ebx, lengthof list1 mov edx, 0 div ebx call writedec mov al, 20h call writechar mov eax, edx call writedec mov al, '/' call writechar mov eax, lengthof list1 call writedec call crlf mov ecx, lengthof list1 sub ecx, 1 mov eax, type list1 mul ecx mov ebx, eax L4: mov edx, ebx mov eax, ecx L5: push [list1 + edx] push [list1 + (edx - type list1)] pop [list1 + edx] pop [list1 + (edx - type list1)] sub edx, 4 LOOP L5 mov ecx, eax push ecx push ebx mov ecx, lengthof list1 mov ebx, 0 mov edx, offset s5 call writestring L6: mov eax, [list1 + ebx] call writedec mov al, ' ' call writechar add ebx, 4 LOOP L6 pop ecx pop ebx LOOP L4
exit main endp end main
OUTPUT:
Please enter a number: 0 Please enter a number: 1 Please enter a number: 2 Please enter a number: 3 Please enter a number: 4 Please enter a number: 5 Please enter a number: 6 Please enter a number: 7 Please enter a number: 8 Please enter a number: 9 The original array: 0 1 2 3 4 5 6 7 8 9 The sum is: 45 The mean is: 4 5/10 After a rotation: 9 0 1 2 3 4 5 6 7 8
ERROR:
Unhandled exception at 0x00403638 in Project.exe: 0xC0000005: Access violation writing location 0x00405FFD.
First shifting goes okay, but after that, it will give me an error. It seems like
L5: push [list1 + edx] push [list1 + (edx - type list1)] pop [list1 + edx] pop [list1 + (edx - type list1)] sub edx, 4 LOOP L5
This part might give me an error, but I don't know because it just should not be.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
