在MIPS中,答案为空时应该返回什么

问题描述

我具有MIPS功能,可以在字符串中查找字符。我不确定如果字符不在字符串中返回什么。在c ++中,我可能会返回-1,但是我不确定这是MIPS中正确的约定。我应该返回0吗?引发错误?还有其他东西吗?

# return the address of the first occurance of the character in a1 in the string at the address in a0
FIND:
move $t0,$a0    # t0 has address
LOOP:
lb $t1,0($t0)   # load current char into mem
beq $t1,$a1,END # check if the current char is the right one
beq $t1,$zero,FAIL # end of string
addi $t0,$t0,1  # move to next char
j LOOP
FAIL:
li $t0,-1  # return -1 as the address
END:
move $v0,$t0    # return
jr $ra

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)