美文网首页
Instructions: Language of the

Instructions: Language of the

作者: 刘东利2020 | 来源:发表于2023-01-24 10:13 被阅读0次

既然提到了返回到初始点(point of origin),为了提升计算机的运算速度,寄存器就被利用了起来:

RISC-V software follows the following convention for procedure calling in allocating its 32 registers:

- x10–x17: eight parameter registers in which to pass parameters or return values.

- x1: one return address register to return to the point of origin.

如何回到初始点呢?作者提到了两个专门用于跳转的指令,第一个是jal:

jal x1, ProcedureAddress // jump to ProcedureAddress and write return address to x1

另一个是jalr:

To support the return from a procedure, computers like RISC-V use an indirect jump, like the jump-and-link instruction (jalr) introduced above to help with case statements:

jalr x0, 0(x1)

中文图书将第一句翻译成“为了支持这种情况下的过程返回” —— 英文没有“这种情况下”,为啥要加上呢?我理解是翻译者在尝试解读两个指令之间的关系:

The jump-and-link register instruction branches to the address stored in register x1—which is just what we want. Thus, the calling program, or caller, puts the parameter values in x10–x17 and uses jal x1, X to branch to procedure X (sometimes named the callee). The callee then performs the calculations, places the results in the same parameter registers, and returns control to the caller using jalr x0, 0(x1).

这里涉及到几个概念:

caller The program that instigates a procedure and provides the necessary parameter values.

callee A procedure that executes a series of stored instructions based on parameters provided by the caller and then returns control to the caller.

return address A link to the calling site that allows a procedure to return to the proper address; in RISC-V it is stored in register x1.

最后,jal也可以用于过程内的无条件跳转:

Since x0 is hard-wired to zero, the effect is to discard the return address:

jal x0, Label // unconditionally branch to Label

相关文章

网友评论

      本文标题:Instructions: Language of the

      本文链接:https://www.haomeiwen.com/subject/ydvrhdtx.html