相关疑难解决方法(0)

ARM:为什么我需要在函数调用时推送/弹出两个寄存器?

我知道我需要在函数调用开始时推送链接寄存器,并在返回之前将该值弹出到Program Couter,以便执行可以从函数调用之前的位置执行.

我不明白的是为什么大多数人通过在push/pop中添加一个额外的寄存器来做到这一点.例如:

push {ip, lr}
...
pop {ip, pc}
Run Code Online (Sandbox Code Playgroud)

例如,这是ARM的官方ARM博客提供的ARM Hello世界:

.syntax unified

    @ --------------------------------
    .global main
main:
    @ Stack the return address (lr) in addition to a dummy register (ip) to
    @ keep the stack 8-byte aligned.
    push    {ip, lr}

    @ Load the argument and perform the call. This is like 'printf("...")' in C.
    ldr     r0, =message
    bl      printf

    @ Exit from 'main'. This is like 'return 0' in C.
    mov     r0, #0      @ Return 0. …
Run Code Online (Sandbox Code Playgroud)

assembly arm

12
推荐指数
2
解决办法
1万
查看次数

标签 统计

arm ×1

assembly ×1