MIPS program that takes an array elements as inline data and prints them in ascending and descending orders
input should be interacive.
I don't know where to fix.... help me to fix.
.text
main:
li $t4, 9999 #$t4 = 9999
la $s0, array #$s0 = address of array[0]
move $a1, $s0 #saving array address in $a1 for later use
addi $s0, -4 # Moved $s0 one word up to accommodate increment
# later
inputLoop:
addi $s0, 4
#print out the prompt
la $a0, askInput
li $v0, 4
syscall
#read in the array element value entered by user
li $v0, 5
syscall
#store the value in array
move $t0, $v0
sw $t0, ($s0)
beq $t0, $t4, ProcessArray
j inputLoop
ProcessArray:
move $s0, $a1 # $s0 = array[0]
lw $s1, ($s0) # load the last element in $s1
addi $s0, 4
lw $s2, ($s0)
beq $s2, $t4, Exit
slt $t5, $s1, $s2 #$t5 = 1 if $s1 < $s2
beq $t5, $0, swap
j ProcessArray
#la $s0, array
Exit:
move $s0, $a1
#printout the array element array[0]
printLoop:
lw $t3, ($s0)
move $a0, $t3
li $v0, 1
syscall
la $a0, comma
li $v0, 4
syscall
addi $s0, 4
bne $t3, $t4, printLoop #Checking for 9999
li $v0, 10
syscall
swap:
move $a0, $s0
sw $s1, 0($a0)
addi $a0, -4
sw $s2, ($a0)
bne $s2, $t4, Exit
j ProcessArray
.data
array: .space 100
arrayAscend: .space 100
arrayDescend: .space 100
askInput: .asciiz "Eneter value of array element or 9999 to end "
output: .asciiz "\nYou entered: "
comma: .asciiz ", "