你的位置:Djed中文网 > BTAF token中文网 > [翻译]ARM汇编简介(六)堆栈和函数-外文翻译-看雪-安全社区|安全招聘|kanxue.com
[翻译]ARM汇编简介(六)堆栈和函数-外文翻译-看雪-安全社区|安全招聘|kanxue.com
- 发布日期:2025-01-04 15:25 点击次数:203 Finally, it is important to understand the use of BL and BX instructions here. In our example, we branched to a leaf function by using a BL instruction. We use the the label of a function as a parameter to initiate branching. During the compilation process, the label gets replaced with a memory address. Before jumping to that location, the address of the next instruction is saved (linked) to the LR register so that we can return back to where we left off when the function max is finished.最后,重要的是理解BL和BX指令在这里的使用。在我们的例子中,我们使用BL指令分支到叶函数。我们使用函数的标签作为参数来启动分支。在编译过程中,标签被替换为内存地址。在跳转到该位置之前,下一条指令的地址被保存(链接)到LR寄存器,这样我们就可以返回到函数max结束时离开的位置。The BX instruction, which is used to leave the leaf function, takes LR register as a parameter. As mentioned earlier, before jumping to function max the BL instruction saved the address of the next instruction of the function main into the LR register. Due to the fact that the leaf function is not supposed to change the value of the LR register during it’s execution, this register can be now used to return to the parent (main) function. As explained in the previous chapter, the BX instruction can exchange between the ARM/Thumb modes during branching operation. In this case, it is done by inspecting the last bit of the LR register: if the bit is set to 1, the CPU will change (or keep) the mode to thumb, if it’s set to 0, the mode will be changed (or kept) to ARM. This is a nice design feature which allows to call functions from different modes.用于离开叶函数的BX指令以LR寄存器作为参数。如前所述,在跳转到函数max之前,BL指令将函数main的下一个指令的地址保存到LR寄存器中。由于叶函数不在执行期间改变LR寄存器的值,所以该寄存器现在可以用于返回父(main)函数。如前一章所解释的,BX指令可以在分支操作期间在ARM/Thumb模式之间进行交换。在这种情况下,它是通过检查LR寄存器的最后一位来完成的:如果位被设置为1,CPU将模式切换(或保持)为Thumb,如果设置为0,则模式将被改变(或保持)为ARM模式。这是一个很好的设计特性,允许从不同模式来调用函数。To take another perspective into functions and their internals we can examine the following animation which illustrates the inner workings of non-leaf and leaf functions.为了从另一个角度观察函数及其内部结构,我们可以看看下面的动画,它说明了非叶和叶函数的内部工作状况。
相关资讯