I am taking a class in Assembly this semester and am currently at a loss. The first two projects I found easy enough but now we are working with strings. I have a basic skeleton for the program that gets input.

strbuf: .space  80               #  Buffer for string being flipped
ann:    .ascii  "Welcome to UpLo\n"
        .asciiz "Type a sentence and I will swap upper/lower case\n"
prompt: .asciiz "New sentence (just return to exit): "

#  Main Program
        li      $v0,4           #  Announce myself with a message
        la      $a0,ann         #    on the terminal.
        li      $v0,4           # Prompt for a new sentence
        la      $a0,prompt
        jal     readstr         # Read the string

        jal     chgcase         # Flip upper/lower case
        jal     wrtstr          # Write the result
        b       loop
done:                           # Get here when all done.
        li      $v0,10          #  "exit" syscall
        li      $v0,8
        la      $a0,strbuf
        li      $a1,80
        jr      $ra
        li      $v0,4
        la      $a0,strbuf
        jr      $ra
        jr      $ra

This succeeds in getting the input and writing it back to the screen. I just need to do a few modifications to the string that is entered. If the user enters nothing then the program exits. Any letters entered are reversed, upper to lower case and vice versa. I know that the difference in a letter's upper and lower case is 0x20, and 0x0a is the hex for a new line(user just typed enter) but I cannot figure out how to use this and the entered string to achieve the desired result. I asked the professor for help and he just told me the differnce is 0x20 hex, make sure the only things to change case are letters, and a new line is 0x0a. I already know all this, it is just the actual conversion that is giving me problems. Any help or hints in the right direction would be appreciated. I feel like I need to navigate the string one byte(character) at a time, and pass each character to a chg subroutine, but I haven't been able to get anything to work

Thank you for your time

PS, the assembly I am coding in is MIPS but I am sure that I can use other assembly code or tips and modify it as needed for my processor.

Instead of relying on a syscall to output a string, is there one to output a character?

If so, use that to practice using a loop to scan a string until a \0 is found.
Then you can make the loop do other things, like say compare a char with 'A' and maybe add 0x20

This article has been dead for over six months. Start a new discussion instead.