【发布时间】:2019-04-08 04:21:34
【问题描述】:
我刚刚开始学习 MIPS 汇编,但我不知道如何有条件地返回到 caller 过程。一个例子将使我的问题更清楚。我有一个程序caller,它在调用multiply 之前做了一些事情,我希望这个程序在multiply 完成后执行other things。我知道如何使用条件跳转到标签,但我想在jal multiply 之后返回caller 而不是beq $t3, 80, caller。我知道,要返回你必须使用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;
}
【问题讨论】:
标签: assembly branch mips mips32 mips64