我刚刚开始学习MIPS汇编,我无法弄清楚,如何有条件地返回caller
程序。一个例子将使我的问题更清楚。我有一个程序caller
,它在调用multiply
之前做了一些事情,我希望这个程序在other things
完成后执行multiply
。我知道如何使用条件跳转到标签,但我想回到beq $t3, 80, caller
而不是caller
,就在jal multiply
之后。我知道,要回来你必须使用jr $ra
,但我可以使用条件来调用吗?
caller:
doing_somehing
jal multiply
other_things
multiply:
beq $t3, 80, caller
lw $t4, array($t3)
mul $t4, $t4, $t1
sw $t4, array($t3)
addi $t3, $t3, 4
j multiply
程序集应该像这个C代码:
void caller()
{
doing_something();
multily();
other_things();
}
void multiply()
{
int i = 0;
while (i < 80)
{
someUnrelated();
i += 4;
}
return;
}
......但我可以用条件来称它吗?
很不幸的是,不行。
只有少数CPU(如8080兼容机(8080,Z80,8085)和ARM)允许基于条件的返回。
你将不得不使用跳转到beq
指令的jr $ra
指令。