Help with mips program that reverses each word.? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help with mips program that reverses each word.?

Hello, I have a problem that has been driving me crazy. I have a program that reads a string and then reverses the string but what I need is the program to reverse each word like: ("10 is ten" becomes "01 si net"). Can anyone help? Here is what I have:
# PROGRAM:

.data # Data declaration section
a_string: .asciiz "desrever eb ot gnirts a si sihT
"

.text # Assembly language instructions
main: la $a0,a_string #base address of string
li $v0,4 #read string
syscall

addi $a1,$zero,32 #pass lenght of string
jal stringreverse #reverse the string

stringreverse:
add $t0,$a0,$zero #starting address
add $t1,$zero,$zero #i = 0
addi $t2,$a1,-1 #j = length-1

loop:
add $t3,$t0,$t1
lb $t4,0($t3) #the lb string[i]
add $t5,$t0,$t2
lb $t6,0($t5) #the lb string[j]
sb $t4,0($t5) #string[j] = string[i]
sb $t6,0($t3) #string[i] = string[j]
addi $t1,$t1,1 #i++
addi $t2,$t2,-1 #j--
#if i>=j then break - $t1 < $t2
slt $t6,$t2,$t1
beqz $t6,loop

exit:
li$v1, 4 #system call to print reversed string
la$a2, 0($a1)
syscall

li $v0, 10
syscall # Exit program

Thanks in advance for any help :)
Sign In or Register to comment.