Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在MIPS中,当答案为空时,我应该返回什么_Mips_Return Value_Conventions - Fatal编程技术网

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

在MIPS中,当答案为空时,我应该返回什么,mips,return-value,conventions,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($t

我有一个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(或在目标平台上无效的某个地址)。如果是布尔值,则返回0。如果是位置,则返回负数。在MIPS中执行与在C/C++中相同的操作。C/C++函数应该能够调用汇编,反之亦然,为了实现这一点,它们必须遵循相同的逻辑函数原型,包括参数和返回值定义。