【问题标题】:Return to the caller function MIPS assembly返回调用函数 MIPS 程序集
【发布时间】: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


    【解决方案1】:

    ...但是我可以使用条件来调用它吗?

    很遗憾没有。

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

    您必须使用跳转到jr $ra 指令的beq 指令。

    【讨论】:

      猜你喜欢
      • 2023-04-06
      • 2016-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-28
      • 2012-06-17
      • 1970-01-01
      相关资源
      最近更新 更多