How to convert all the lowercase letters to Uppercase letters in MIPS Assembly Language program

A P S picture A P S · Dec 18, 2015 · Viewed 10.6k times · Source

Excuse me, can someone help me on this? I need to convert all the lowercase letters such as this "Hello how are you?" to "HELLO HOW ARE YOU?",

Here is what I have so far:

.data
firsttyped: .asciiz ""
newline: .asciiz "\n"

.text
main:
    li $v0, 8
    li $a1, 20
    la $a0, firsttyped
    syscall

    li $v0, 4
    li $t0, 0

loop:
    lb $t1, firsttyped($t0)
    beq $t1, 0, exit
    sub $t1, $t1, 32
    sb $t1, firsttyped($t0)
    addi $t0, $t0, 1
    j loop


exit:
    li $v0, 4
    la $a0, firsttyped
    syscall

    li $v0, 10
    syscall

Can someone help me out on this please? I need to prevent that error the underlined e from coming.

By the way I do not understand psuedo codes.

Answer

gusbro picture gusbro · Dec 18, 2015

You should:

  • reserve space for the input buffer
  • check whether each character is a lower case letter
  • skip the character if it's not a lower case letter
  • make it upper case if it was lower case

To do so you would: replace .asciiz "" from firsttyped with:

 firsttyped: .space 20

Add the following lines after beq $t1, 0, exit

blt $t1, 'a', not_lower
bgt $t1, 'z', not_lower

and add the label not_lower before addi $t0, $t0, 1:

not_lower: