返回调用函数MIPS程序集

问题描述 投票:0回答:1

我刚刚开始学习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;
}
assembly branch mips mips32 mips64
1个回答
3
投票

......但我可以用条件来称它吗?

很不幸的是,不行。

只有少数CPU(如8080兼容机(8080,Z80,8085)和ARM)允许基于条件的返回。

你将不得不使用跳转到beq指令的jr $ra指令。

© www.soinside.com 2019 - 2024. All rights reserved.