Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MIPS code to sort a string

Status
Not open for further replies.

Fyresoul

Programmer
Nov 4, 2004
2
US
I've written sorts before, just not in assembly.
I know how to get the string (user input or hardcoded) into a register and how to work my way through it, but I'm not sure how to make it get sorted, or sort into another register.
Code:
data
str:	.asciiz "zghfjsdkalqpwoeirutyvn"
	.text
	.globl main
main:	
	la $t2,str	
nextCh:	lb $t0,($t2)	# fetch char
	beqz $t0, Done  # 0x0 terminates string goes to 			# exit
	#sorting/swapping goes here ^_^;;

	add $t2,1	#increment $t2 to get to next char
	j nextCh
Done:
	li $v0,10
	syscall
Any help will be appreciated
 
ok so I've bubble sorted the string.. is there a way to print out individual characters from the string?
this code prints out my array as a string, but I want to access the individual chars in it.
Code:
# Print the sorted array 

         li $v0, 4 
         la $a0, sorted         # Print "Sorted: " 
         syscall 
         la $s0, sarray        #location in memory of my now sorted array
         lw $s1, count
#loop4:   lb $a0, 0($s0)
	 move $a0, $s0     #commenting this line and uncommenting the others prints (null)
         li $v0, 4 
         syscall 
#         li $v0, 4 
#         la $a0, nl 
#         syscall 
#         add $s0, $s0, 1 
#         addi $s1, $s1, -1 
#         bne $s1, $0, loop4

Thank you, Fyresoul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top