Here's what I have so far.I've Commented it to the best of my ability, or at least to what i think is going on....
Heres one test of the program(it semi-sorts)
Please Enter Your Letters:
dfgfdgdddfg
Result: ddffddgddfg
Code:
##############################################################################################################
.data
insert:
.word 4
string_ask:
.asciiz "\nPlease Enter Your Letters:\n " ##address = string_ask
string_return:
.asciiz "\nResult: " ##address = string_return
.text ##enables text input/output
main:
la $a0, string_ask
li $v0, 4
syscall
#-----------------------Read in String----------------------------------#
li $v0, 8 ##Read in String
move $s0, $a0 ##Copy to $s0
syscall
#-----------------------Sort the string---------------------------------#
move $v0, $s0 ##Copy string to $v0 to pass to sort function
jal sort ##Sort the string
move $s0, $v0 ##Save sorted string into $s0
#---------------------Print the sorted string---------------------------#
la $a0,string_return ##
li $v0, 4
syscall
move $a0, $s0
li $v0, 4
syscall
li $v0, 10 ## return from main routine
syscall
.end main
#####################################~END MAIN~###############################
#----------------------Bubble Sort---------------------------------------#
sort:
move $t9, $v0 ## t9=Address of string
lw $t1,insert ## $t1 = insert
li $t0, 0 ## $t0 = 0 (i)
loop1:
beq $t1, $t0, exit ## if $t0 == insert, exit
addi $t4, $t0, -1 ## $t4(J) = counter-1
loop2:
bltz $t4, exit2 ## j < 0
mul $t5, $t4, 2 ## $t5 = 2 * j
add $t5, $t9, $t5 ## $t5 = a[2j]
lb $t2, 0($t5) ## $t2 = a[j]
lb $t3, 1($t5) ## $t3 = a[j+1]
ble $t3, $t2, else ## a[j+1] >= a[j]
j swap
else:
addi $t4, -1 ## --j
j loop2
exit:
move $v0, $t9 ##Return $t9 (sorted string)
jr $ra
exit2:
addi $t0, 1 ## ++i
j loop1
swap:
sb $t3, 2($t5)
sb $t2, 1($t5)
j loop2
#########################################################################################################