无法将答案存储在 MIPS 中
Cannot store the answer to memory in MIPS
我正在尝试在 MIPS 中编写一个函数,它将接受一个字符串和 return 字符串中的字符数。这是我目前所拥有的
# 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 == '[=10=]' 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" 行给我一个语法错误。有人可以告诉我我的程序有什么问题吗?谢谢
语法错误通常是由拼写错误引起的,就像您的情况一样。你不小心写了 vo
而不是 v0
.
我正在尝试在 MIPS 中编写一个函数,它将接受一个字符串和 return 字符串中的字符数。这是我目前所拥有的
# 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 == '[=10=]' 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" 行给我一个语法错误。有人可以告诉我我的程序有什么问题吗?谢谢
语法错误通常是由拼写错误引起的,就像您的情况一样。你不小心写了 vo
而不是 v0
.