MIPS中的函数(过程) [英] the functions (procedures) in MIPS
问题描述
我是MIPS语言的新成员,我不明白MIPS汇编语言中的函数(过程)是如何工作的。这里是但我会指定我的问题:
-
什么:
-
jal
-
jr
li>
-
$ ra
语言和重要的东西
-
What does:
jal
jr
$ra
mean in mips language and the important thing
- How can we use them when we want to create a function or (procedure)?
$
$我们如何在创建函数或(过程)时使用它们? b $ b
首先,您可能需要检查这个快速MIPS参考。它真的帮助了我。第二,解释 jal
, jr
以及 $ b code> $ RA 。 jal< label>
的作用是跳转到标签
标签并存储程序计数器(把它当作当前指令的地址)存放在 $ ra
寄存器中。现在,当你想从标签
返回到最初的位置时,只需使用 jr $ ra
。
下面是一个例子:
.text
main :
li $ t0,1
jal程序#调用程序
li $ v0,10
系统调用
程序:
li $ t0 ,3
jr $ ra#return
在SPIM仿真器中运行时会注意到在 $ t0
中剩下的值是3,即在所谓的过程中加载的值。
希望这有助于。
I'm new in MIPS language and I don't understand how the functions (procedures) in the MIPS assembly language work. Here are but I will specify my problem :
Firstly, you might want to check this quick MIPS reference. It really helped me.
Secondly, to explain jal
, jr
and $ra
. What jal <label>
does is jump to the label
label and store the program counter (think of it as the address of the current instruction) in the $ra
register. Now, when you want to return from label
to where you initially were, you just use jr $ra
.
Here's an example:
.text
main:
li $t0, 1
jal procedure # call procedure
li $v0, 10
syscall
procedure:
li $t0, 3
jr $ra # return
You will notice when running this in a SPIM emulator that the value left in $t0
is 3, the one loaded in the so-called procedure.
Hope this helps.
这篇关于MIPS中的函数(过程)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!