THe following is a program i have been working on with the help of my notes and
ID: 3712064 • Letter: T
Question
THe following is a program i have been working on with the help of my notes and google but i can seem to get it to work can someone take a look at it and tell me what i did wrong and how it should be.
Alphabetize a string of characters input from the keyboard
Analyzes a string of characters input from the keyboard and outputs ONLY the lower case letters in alphabetical order. The program will take only up to 17 characters regardless of the string you attempt to input. Program must ignore anything other than lower case characters in the string of 17 characters taken from the input attempted.
The input string should be labeled “string 1” in the data statements with a “.space” directive to reserve enough bytes of memory space so that you will still have a null-terminated string, since “.space” clears all byte spaces to 0.
. Input the string from the keyboard using a syscall 8. They should be stored in the reserved space labeled “string 1.”
. Screen and alphabetize the string and output the alphabetized lowercase letters to the simulated console.
. The output of alphabetized letters is preceded by the statement: “The alphabetized string is: ”
Before ending the program, include a prompt to ask the user if they want to run again using syscall 12. If the answer is y (for Yes), it starts over. If the answer is anything but y, the program prints “Program terminated” message and stops.
qtspim code-------------------------------------------------------------------->
.data
string_ask: .asciiz " Enter string: "
string_return: .asciiz " Result: "
terminated: .asciiz "Do you want to try again (y for yes)?"
in_name: .space 31 ## space for input string
.text
.globl main
main:
la $a0,string_ask ## print prompt string
li $v0,4
syscall
la $a0,in_name ## read the input string
li $a1,31 ## at most 30 chars + 1 null char
li $v0,8
syscall
la $a0,string_return ## write output message
li $v0,4
syscall
la $t0,in_name # # $t0 <=in_name
loop1:
lb $t1,0($t0)
beqz $t1,exit_loop1 ## if $t1=0, exit
blt $t1,'a',no_change ## $t1 < a,next
bgt $t1,'z',no_change ## $t1 > z,next
addiu $t1,$t1,-32 ## convert to uppercase: 'A'-'a'=-32
sb $t1,0($t0)
no_change:
addiu $t0,$t0,1 ## increment pointer, i++
j loop1
exit_loop1:
la $a0,in_name ## output converted string
li $v0,4
syscall
li $v0,10 ## exit
syscal
Explanation / Answer
instead of lb $t1,0($t0) write $t1,0($t1)
beacause we want only lowercase latters and we want to terminate the program at last.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.