Assembly 带有堆栈的MIPS回文,错误结果。更新代码。

Assembly 带有堆栈的MIPS回文,错误结果。更新代码。,assembly,stack,mips,palindrome,qtspim,Assembly,Stack,Mips,Palindrome,Qtspim,我正在尝试构建MIPS回文并实现堆栈。程序要求用户输入一个字符串,以确定它是否是回文。我已经试着调试了一段时间,但没有找到解决方案。更新代码 str: .space 16 prompt: .asciiz "Enter a string: " yespal: .asciiz "This is a palindrome.\n" nopal: .asciiz "This is not a palindrome.\n" .text main: addi

我正在尝试构建MIPS回文并实现堆栈。程序要求用户输入一个字符串,以确定它是否是回文。我已经试着调试了一段时间,但没有找到解决方案。更新代码

str:    .space  16
prompt: .asciiz "Enter a string: "
yespal: .asciiz "This is a palindrome.\n"
nopal:  .asciiz "This is not a palindrome.\n"


            .text
main:   
    addiu   $sp, $sp, -8    #Allocating space
    li      $v0, 4          #promt user to enter string
    la      $a0, prompt
    syscall
    li      $v0, 8          #read in string
    li      $a1, 16         #string length 16 characters max
    la      $a0, str        #address of string loads into $a0
    syscall 
    jal     pal
    sw      $ra, 4($sp)     #store current value
    sw      $a0, 0($sp)     #store string memory address

    lw      $ra, 4($sp)
    move    $t9, $ra
    addi    $sp, $sp, 8
    bgtz    $t9, yess
    beqz    $t9, nopa


pal:    
    la      $t0, str        #load address of string
    addiu   $sp, $sp, -12   #Allocate more space
    sw      $t0, 0($sp)     #store string memory address
    sw      $ra, 4($sp)     #store current value
    jal     nchars          #go to nchars function

    lw      $ra, 4($sp)     #restore printable character value
    lw      $t1, 8($sp)     #move value to register
    lw      $t7, 12($sp)    #return current string value
    addi    $sp, $sp, 12    #release the extra stack

    bge     $t1, $t7, palin
    lbu     $s3, 0($t0)     #pointer 1. the first char
    lbu     $s4, 0($t7)     #pointer 2. the last char
    addi    $t1, $t1, 1     #increase pointer 1 by 1
    addi    $t7, $t7, -1    #decrease pointer 2 by 1
    bne     $t1, $t7, noPal

palin:  
    li      $s8, 1
    sw      $s8, 4($sp)
    jr      $ra

 noPal:  
     li     $s8, 0
    sw      $s8, 4($sp)
    jr      $ra


nchars: 
    li      $t8, 0      #register counter set to 0
    lw      $t9, 0($sp) #pointer for start of string
 lloop: 
    lb      $s0, 0($t9) #load current character
    beq     $s0, $0, endln
    addi    $t9, $t9, 1 #move pointer to next character
    addi    $t8, $t8, 1 #add 1 to counter
    j       lloop   
 endln: 
    sw      $t8, 8($sp) #store counter for return in 8($sp)
    sw      $t9, 12($sp)    #store current value of string
    jr      $ra         #return counter to pal function


yess:   
    li      $v0, 4          #print result for yes
    la      $a0, yespal
    syscall
    li   $v0, 10         
    syscall 

nopa:   
    li      $v0, 4          #print result for no
    la      $a0, nopal
    syscall
    li   $v0, 10         
    syscall 

您应该更好地注释代码。另外,告诉我们问题是什么。调试时,请验证每条指令是否都在执行您想要的操作。您正在滥用pal中的la伪指令:。你想要lw lh/lb或者移动。我更新了评论,谢谢你的建议。目前正在尝试改变一些事情。