..data keyboardBuffer: .space 50 test1: .asciiz "WORD is BAD" .text main: # Test case 1 la $a0, test1 jal subroutine li $v0, 4 syscall # Endline li $a0, '\n' li $v0, 11 syscall # Exit li $v0, 10 syscall # Address of argument stored in $a0 # Return value also in $a0 # %t0 - pointer to current char # %t1 - current char # $t2 - current number from buffer # $fp - buffer for CAPITAL LETTERS # $sp - pointer to start of the buffer subroutine: move $t0, $a0 # Copy address of string move $fp, $sp # Set frame pointer findLoop: lbu $t1, ($t0) # Load char beq $t1, ' ', endFindLoop # End loop if char is less than white space bltu $t1, 'A', skipSave # Skip saving char if NaN bgtu $t1, 'Z', skipSave sb $t1, ($fp) addiu $fp, $fp, -1 # Decrement stack sb $t1, ($fp) skipSave: addiu $t0, $t0, 1 j findLoop endFindLoop: move $t0, $a0 # Set pointer to begin of the string replceLoop: lbu $t1, ($t0) # Load char bltu $t1, ' ', return # End loop if char is less than white space bltu $t1, 'A', skipReplace # Skip saving char if NaN bgtu $t1, 'Z', skipReplace addiu $fp, $fp, 1 # Increment stack lbu $t2, ($fp) sb $t2, ($t0) beq $t1, '0', findLoop skipReplace: addiu $t0, $t0, 1 j replceLoop return: jr $ra
所以本质上我需要转换
WORD is BAD
进入
DROW is DAB而我得到
DROW is为什么它用大写字母压倒第二个单词?我不知道:(