首页 > 解决方案 > 无法将答案存储在 MIPS 中

问题描述

我正在尝试在 MIPS 中编写一个函数,该函数将接收一个字符串并返回字符串中的字符数。这是我到目前为止所拥有的

# Program to calculate string length of any given string

            .data
mystring:   .asciiz "Hello, World!"
answer:     .word 0

            .text
            .globl main
main:       la      $a0, mystring   # Load base adress of the string into function argument

            jal     strlen          # jump to strlen and save position to $ra

            sw      $vo, answer     # Store the answer to memory

            li      $v0, 10         #exit
            syscall


strlen:     li      $v0, 0          # Initialize counter = 0

stringLoop: lb      $t0, 0($a0)     # Load first word of the string

            beq     $t0, $zero, end # if $t0 == '\0' then exit the loop

            addi    $a0, $a0, 1     # Increment the address (go to the next character)

            addi    $v0, $v0, 1     # Increment the counter

            b       stringLoop

end:        jr      $ra             # Return to main program

每次我尝试使用 QtSpim 运行它时,都会在“sw $vo, answer”行出现语法错误。有人可以告诉我我的程序有什么问题吗?谢谢

标签: assemblymipsmips32

解决方案


语法错误通常是由拼写错误引起的,就像您的情况一样。你不小心写成vov0.


推荐阅读