ARM 中的 PUSH 和 POP 顺序 [英] PUSH and POP order in ARM

查看:42
本文介绍了ARM 中的 PUSH 和 POP 顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解 ARM 程序集中函数的开始和结束:

I'm trying to understand the start and end of functions in ARM assembly:

PUSH {R0-R2, LR}
POP {R0-R2, PC}

在 IDA 中查看这段代码是我所理解的(假设 SP 为 0x100):

Looking at this piece of code in IDA here's what I understood (Lets assume SP is 0x100):

PUSH R0 ; sp = 0xFC
PUSH R1 ; sp = 0xF8
PUSH R2 ; sp = 0xF4
PUSH LR ; sp = 0xF0
POP R0 ; sp = 0xF4
POP R1 ; sp = 0xF8
POP R2 ; sp = 0xFC
POP PC ; sp = 0x100

似乎 PC 得到了 R0 的值,而它应该得到 LR 的值.
PC不应该得到LR的值吗?

It seems like PC gets the value of R0, when it should get the value of LR.
Shouldn't PC get the value of LR?

推荐答案

当你 PUSH 或 POP 一堆寄存器时,它们总是以相同的相对位置进入内存,无论方向如何.最低编号的寄存器存储在最低地址并从最低地址加载.所以在这个例子中,除了 LR->PC 之外,一切都会回到原来的寄存器中.

When you PUSH or POP a bunch of registers, they always go into memory in the same relative positions, regardless of direction. The lowest-numberd register is stored at and loaded from the lowest address. So in this example everything will go back to the original register, except LR->PC.

换一种说法,将 PUSH 想象成存储 {LR,R2,R1,R0}.

To put that another way, imagine the PUSH as if it was storing {LR,R2,R1,R0}.

请参阅您最喜欢的 Arm 32 位处理器系列的用户指南/指令集参考;LDM 和 STM.

See the User Guide / Instruction Set reference for your favourite Arm 32-bit processor series; LDM and STM.

这篇关于ARM 中的 PUSH 和 POP 顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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