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

时间:2020-10-03 09:23:31

标签: mips return-value conventions

我具有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

0 个答案:

没有答案
相关问题