I'm trying to toggle a simple user given text from lower case to upper and vice versa. Example: “Hello” after running it becomes “hELLO” essentially toggling cases. The program currently only converts from lower case to upper. My question is, how can the transition from Uppercase to lowercase be implemented based on what's already written. Forgive me if I’m doing anything wrong. Am fairly new to this. This is what I currently have:
.data
promp: .asciiz "Enter string: "
str: .space 81
toogle_msg: .asciiz "The result is "
.text
.globl main
main:
li $v0,4 # syscall code to print
la $a0,promp # promp message tag
syscall # print promp
li $v0, 8 #syscall code to read string
li $a1, 81 # space for string
la $a0, str # str message tag
syscall # print
li $v0, 4
li $t0, 0
loop:
lb $t1, str($t0)
beq $t1, 0, exit # go to exit if $t1=0
blt $t1, 'a', case # go to case if $t1>a
bgt $t1, 'z', case # go to case if $t1<z
sub $t1, $t1, 32 # subtract 32 and save in $t1
sb $t1, str($t0)
case:
addi $t0, $t0, 1
j loop # go to loop
exit:
li $v0,4 # syscall code to print
la $a0,toogle_msg # toogle message tag
syscall # print toggle_msg
li $v0, 4 # syscall code to print
la $a0, str # str message tag
syscall # print str
li $v0, 10 # syscall code to exit
syscall # exit