MIPS:从字符串中删除非字母数字字符

MIPS:从字符串中删除非字母数字字符,mips,Mips,我正在用MIPS编写一个程序,它将确定用户输入的字符串是否是回文。它有三个子例程正在构造中。 以下是主要代码块、要遵循的子程序以及相关信息: .data Buffer: .asciiz " " # 80 bytes in Buffer intro: .asciiz "Hello, please enter a string of up

我正在用MIPS编写一个程序,它将确定用户输入的字符串是否是回文。它有三个子例程正在构造中。
以下是主要代码块、要遵循的子程序以及相关信息:

.data
Buffer: .asciiz "                                                                                "  # 80 bytes in Buffer
intro:  .asciiz "Hello, please enter a string of up to 80 characters.  I will then tell you if that string was a palindrome!"
        .text
main:
    li  $v0, 4      # print_string call number
    la  $a0, intro  # pointer to string in memory
    syscall
    li  $v0, 8      #syscall code for reading string
    la  $a0, Buffer #save read string into buffer
    li  $a1, 80     #string is 80 bytes long
    syscall
    li  $s0, 0      #i = 0
    li  $t0, 80     #max for i to reach
    la  $a0, Buffer
    jal stripNonAlpha
    li  $v0, 4      # print_string call number
    la  $a0, Buffer # pointer to string in memory
    syscall
    li  $s0, 0
    jal findEnd
    jal toUpperCase
    li  $v0, 4      # print_string call number
    la  $a0, Buffer # pointer to string in memory
    syscall 
首先,它应该从前面的字符串中删除所有非字母数字字符,但是当它遇到指定要删除的字符时,后面的所有字符都将被删除

stripNonAlpha:
    beq $s0, $t0, stripEnd  #if i = 80 end
    add $t4, $s0, $a0       #address of Buffer[i] in $t4
    lb  $s1, 0($t4)     #load value of Buffer[i]
    addi    $s0, $s0, 1     #i = i + 1
    slti    $t1, $s1, 48        #if ascii code is less than 48
    bne $t1, $zero, strip   #remove ascii character
    slti    $t1, $s1, 58        #if ascii code is greater than 57
                    #and
    slti    $t2, $s1, 65        #if ascii code is less than 65
    slt $t3, $t1, $t2       
    bne $t3, $zero, strip   #remove ascii character
    slti    $t1, $s1, 91        #if ascii code is greater than 90
                    #and
    slti    $t2, $s1, 97        #if ascii code is less than 97
    slt $t3, $t1, $t2
    bne $t3, $zero, strip   #remove ascii character
    slti    $t1, $s1, 123       #if ascii character is greater than 122
    beq $t1, $zero, strip   #remove ascii character
    j   stripNonAlpha       #go to stripNonAlpha
strip:
    #add    $t5, $s0, $a0       #address of Buffer[i] in $t5
    sb  $0, 0($t4)      #Buffer[i] = 0
    #addi   $s0, $s0, 1     #i = i + 1
    j   stripNonAlpha       #go to stripNonAlpha
stripEnd:
    la  $a0, Buffer     #save modified string into buffer
    jr  $ra         #return
其次,它应该将所有小写字符转换为大写

toUpperCase:
    beq     $s0, $s2, upperEnd
    add $t4, $s0, $a0
    lb  $s1, 0($t4)
    addi    $s1, $s1, 1
    slti    $t1, $s1, 97
    #beq    $t1, $zero, upper
    slti    $t2, $s1, 123
    slt $t3, $t1, $t2
    bne $t1, $zero, upper
    j   toUpperCase
upper:
    add $t5, $s0, $a0
    addi    $t6, $t6, -32
    sb  $t6, 0($t5)
    j   toUpperCase
upperEnd:
    la  $a0, Buffer
    jr  $ra
检查字符串是否为回文的最后一个子例程目前还没有完成。我很难找到字符串的结尾,因为我不确定PC-SPIM使用什么作为回车符


感谢您的帮助,我觉得我的大部分问题都是由于一些愚蠢和愚蠢的事情造成的,所以请随时指出任何问题,无论这些问题有多小。

您可以通过这样做来发现其价值:

syscall to reading a string
mov first value to $2
check the value of $2 with PC-SPIM or a debugger

呃,这是一个非常古老的问题,但问题是你用空字符替换非字母数字字符,这将在该点终止字符串