MIPS中的函数(过程) [英] the functions (procedures) in MIPS

查看:802
本文介绍了MIPS中的函数(过程)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MIPS语言的新成员,我不明白MIPS汇编语言中的函数(过程)是如何工作的。这里是但我会指定我的问题:


  1. 什么:




    • jal

    • jr li>
    • $ ra



    语言和重要的东西


  2. $
    $我们如何在创建函数或(过程)时使用它们? 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 :

    1. What does:

      • jal
      • jr
      • $ra

      mean in mips language and the important thing

    2. How can we use them when we want to create a function or (procedure)?

    解决方案

    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屋!

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