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

how can I write a MIPS program that ask user to input n (a posetive number less

ID: 3669253 • Letter: H

Question

how can I write a MIPS program that ask user to input n (a posetive number less than or equal to 10) the number of element of array, creates the array, finds and prints the median number in the array. (assuming the entries are in ascending order). and please with comments what each statement does.

A sample of input and output would be:

How many number you like to enter: 9

===============================

Enter number 1: 10

Enter number 2: 20

Enter number 3: 30

Enter number 4: 40

Enter number 5: 50

Enter number 6: 60

Enter number 7: 70

Enter number 8: 80

Enter number 9: 90

===============================

The median is: 50

===============================

Explanation / Answer

.text
.global main
main:
sub sp, sp, #4
str lr, [sp, #0]

;Prompt
ldr r0, =prompt
bl printf

;Scanf
ldr r0, =format4
sub sp, sp, #4
mov r1, sp
bl scanf
ldr r4, [sp, #0]
add sp, sp, #4


;Prompt
ldr r0, =prompt
bl printf

;Scanf
ldr r0, =format4
sub sp, sp, #4
mov r1, sp
bl scanf
ldr r5, [sp, #0]
  


;Prompt
ldr r0, =prompt
bl printf

;Scanf
ldr r0, =format4
sub sp, sp, #4
mov r1, sp
bl scanf
ldr r6, [sp, #0]
add sp, sp, #4


;Prompt
ldr r0, =prompt
bl printf

;Scanf
ldr r0, =format4
sub sp, sp, #4
mov r1, sp
bl scanf
ldr r7, [sp, #0]
add sp, sp, #4

;Now you have the 4 numbers in r4,r5,r6,r7


;Compute average
mov r1, r8
asr r1, #2
ldr r0, =format2
bl printf


format2:
.asciz "Average is %d "
format4:
.asciz "%d"
prompt:
.asciz "Enter A Number "