*帮助。我陷入了困境。我怎么纠正它?
读取字符串并将其存储在内存中。将字符串长度限制为100个字符。然后,将每个字母转换为数字。字母'A'或'a'等于1.字母'B'或'b'等于2.最后,字母'Z'或'z'等于26.所有其他字符,数字或空格应该丢弃(不计算在内)。将字符串值计算为所有字母值的总和,并将字符串值显示为整数。最后,询问用户是否要重复该程序。 这是一个示例运行:
Enter a string of at most 100 characters:
MIPS programming is fun.
String value = 257
Repeat (Y/N)? n
代码:
.data
again: .asciiz "Repeat (Y/N)? "
Prompt: .ascii "Enter a string of at most 100 characters: "
answer: .space 256
.text
.globl main
main:
#addi $t0, $zero, 0 #initial i=0
while:
beq $t0, 'n', exit
beq $t0, 'N', exit
jal printWord
#addi $t0, $t0,1
li $v0, 4
la $a0, again
syscall
la $a0, answer
li $a1, 3
li $v0, 8
syscall
lb $t0, 0($a0)
j while
exit:
li $v0, 10
syscall
#function call
printWord:
la $a0, Prompt
li $v0, 4 #4 print string from prompt
syscall
li $a1, 101 #only 100 characters can be input
li $v0, 8 #8 read string from prompt
syscall
li $v0, 4 #1 print string entered
syscall
jr $ra