Write a MIPS program to ask the user to input the number of
Write a MIPS program to ask the user to input the number of elements of array. The user input should be a positive number less than or equal to 10. Then your program should ask the user to fill up the array and then print the content of array in reverse order. The program must check to see if a negative number of elements was entered.
Solution
Below is the code for the given MIPS program.
.data
MyArray: .space 40
msg1: .asciiz \"Enter number of elements in the array less than or equal to 10\"
msg2: .asciiz \"Enter each number in the array. Make sure you enter a positive integer\"
msg3: .asciiz \"Array in reversed order are: \"
.global main
.text
main:
#Prompt user to enter the number of elements in array
li $v0, 4
la $a0, msg1
syscall
#Taking user input
li $v0, 5
syscall
# Storing the value of array length in t0
move $t0, $v0
#taking user input in the array
li $v0, 4
la $a0, msg2
syscall
addi $t2,$zero, 1
addi $t3,$zero, 0
while:
beq $t2, $t0, exit
addi $t2, $t2, 1
li $v0, 5
syscall
move $t4, $v0
sw $t4, MyArray($t3)
addi $t3, $t3, 4
j while
exit:
li $a0, 4
mul $t5, $a0, $t0
sub $t5, $t5, 4
#printing the array in reverse
li $v0, 4
la $a0, msg3
syscall
while:
beg $t5 , 0 exit
lw $t7 , MyArray($t5)
#printing current number
li $v0, 1
move $a, $t7
syscall
j while
exit:

