2

すべての小文字を大文字にし、ユーザーが文字列に入力したすべての大文字を小文字にするプログラムがあります。文字値に 32 を加算または減算して、目的の文字を取得します。私の問題は、文字列内で何も変更されないことです。何を変更するかについて何か提案はありますか?

.data
prompt: .asciiz "\n\nEnter an string of characters: "
result: .asciiz "\n\nHere is the string you entered: "
after_sort: .asciiz "\n\nHere is the string after the case sorting: "
buffer: .space 80
.text

main:

#Prints the prompt string
li $v0, 4
la $a0, prompt 
syscall 

#reads string from user and saves in $a0
li $v0, 8
la $a0, buffer
li $a1, 80
syscall

#Prints the result string
li $v0, 4 
la $a0, result 
syscall

#Prints the string entered by the user
la $a0, buffer 
li $v0, 4
syscall


li $t0, 0 # t0 = i = 0
for_loop:
slti $t1, $t0, 80 # t1 = 1 if and only if t0 < 80
beq $t1, $0, for_loop_done

slti $t2, $a0, 91
li $t3, 1
beq $t2, $t3, upper #if the character value is less than 91 branch to upper addition
bne $t2, $t3, lower

upper:
addi $a0, $a0, 32 #adds 32 to the character value to lowercase it

lower:
subi $a0, $a0, 32 #subtracts 32 from the character value to capitalize it

addi $t0, $t0, 1

j for_loop
for_loop_done:

#Prints the result string
li $v0, 4 
la $a0, after_sort 
syscall

#Prints the string entered by the user
la $a0, buffer 
li $v0, 4
syscall

exitProgram:    li $v0, 10  # system call to
    syscall         # terminate program
4

3 に答える 3