In: Computer Science
For Project 2, write a program for MIPS that performs the following steps. It
1. Receives a string of upper- and/or lowercase letters from keyboard (user types the letters on the SPIM console window).
2. Stores ASCII codes of the letters in stack.
3. Stop receiving letters when ? is typed by the user.
4. Converts uppercase letters to their lowercase letters and vice versa, and prints the converted string on the SPIM console window.
Assume only valid inputs are typed by the user (i.e., only alphabetic characters and ?). So, your program is not responsible for a wrong input; garbage in, garbage out (GIGO).
Greetings!!
Code:
.data
prompt: .asciiz "Enter the string of your choice: "
string: .space 250
size: .byte 250
.text
#display prompt message
la $a0,prompt
li $v0,4
syscall
#read string
la $a0,string
li $a1,250
li $v0,8
syscall
#processing
loop:
lb $t0,0($a0) #load byte
beq $t0,0x0a,end #if newline then goto end
beq $t0,32,skip #if space then goto
skip
bgt $t0,0x7B,invalid #if greaterthan upperlimit goto
invalid
blt $t0,0x40,invalid #if less than lower limit goto
invlid
bgt $t0,0x60,makeupper #if greaterthan 60 goto
makeupper
addi $t0,$t0,0x20 #smaller and hence add 0x20 or 32 to
make upper
j skip
makeupper:
addi $t0,$t0,-32 #if upper, convert to lower by
subtracting -32
skip:
sb $t0,0($a0) #store byte
addi $a0,$a0,1 #increment array
index
j loop
#repeat
invalid:
end:
#display string
la $a0,string
li $v0,4
#termination
syscall
li $v0,10
syscall
Output screenshot:
Hope this helps