MIPS汇编语言 - 调用一个函数,而无需使用“日航”​​的 [英] MIPS assembly language - Calling a funcion without the use of 'jal'

查看:433
本文介绍了MIPS汇编语言 - 调用一个函数,而无需使用“日航”​​的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要调用一个函数,但由于某些原因,我现在允许使用
JAL 指令。有没有办法做到这一点?

I want to call a function but for some reasons I'm now allowed to use the jal instruction. Is there a way to do that?

这是我的想法是必须要以某种方式获取程序计数器的 $ RA 价值
然后只需使用Ĵ功能,所以像这样

An idea I had was to somehow get the value of the Program Counter in $ra and then just use j function, so something like this

                   # somehow $ra = address of next instruction
addi $ra, $ra, 8   # word length is 32 bytes so $ra gets the address of 
                   # the next instruction after 'j function'
j function
                   # continue here after function ends

function:
    # do stuff
    jr $ra

感谢

推荐答案

如果您查找任何引用 JAL 指令的行为,实在是小巫见大巫效仿。你可能知道,反正 JAL $ RA 保存返回地址,这就是为什么你可以从函数中使用返回 JR $ RA 。因此,所有你需要做的是,解决自己的商店,那么你可以使用Ĵ。例如:

If you look up the behavior of the jal instruction in any reference, it is trivial to emulate it. You probably know it anyway that jal stores the return address in $ra, which is why you can return from functions using jr $ra. Thus, all you need to do is store that address yourself and then you can use j. For example:

    la $ra, continue
    j function
continue:
    ...

这篇关于MIPS汇编语言 - 调用一个函数,而无需使用“日航”​​的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆